nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH V2] wrapping: improve the persistence of the prepend


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH V2] wrapping: improve the persistence of the prepending behavior
Date: Mon, 22 Apr 2019 13:44:31 +0200

V2: The spillover line is now per buffer, so you can even switch
    between buffers, and prepending will continue when you return.

Now you can have a look elsewhere in the buffer (and even delete
or paste stuff there) and when you return to the original line
and continue typing, any spillover from automatic hard-wrapping
will spill over onto the same line it spilled over to before.

You can even switch to a different buffer and return and continue
typing, and stuff will still spill over to the same line.

In the bargain, this gets rid of a bit of flag-resetting code that
was run for many keystrokes, in most cases needlessly.

See https://savannah.gnu.org/bugs/?56189 for more motivation.
---
 src/files.c |  3 +++
 src/nano.c  | 11 -----------
 src/nano.h  |  4 ++++
 src/proto.h |  1 -
 src/text.c  | 21 ++++-----------------
 5 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/src/files.c b/src/files.c
index f9a4fd6b..f6698c0c 100644
--- a/src/files.c
+++ b/src/files.c
@@ -95,6 +95,9 @@ void make_new_buffer(void)
        openfile->current_y = 0;
 
        openfile->modified = FALSE;
+#ifdef ENABLE_WRAPPING
+       openfile->spillage_line = NULL;
+#endif
 #ifndef NANO_TINY
        openfile->mark = NULL;
 
diff --git a/src/nano.c b/src/nano.c
index e775a763..d5dd1e1b 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1781,9 +1781,6 @@ void do_input(void)
                } else
 #endif
                {
-#ifdef ENABLE_WRAPPING
-                       linestruct *was_next = openfile->current->next;
-#endif
 #ifndef NANO_TINY
                        linestruct *was_current = openfile->current;
                        size_t was_x = openfile->current_x;
@@ -1813,14 +1810,6 @@ void do_input(void)
                                        also_the_last = FALSE;
                        }
 #endif
-#ifdef ENABLE_WRAPPING
-                       /* If the cursor moved to another line and this was not 
caused
-                        * by adding characters to the buffer, clear the 
prepend flag. */
-                       if (openfile->current->next != was_next &&
-                                                       shortcut->func != 
do_tab &&
-                                                       shortcut->func != 
do_verbatim_input)
-                               wrap_reset();
-#endif
 #ifdef ENABLE_COLOR
                        if (!refresh_needed && !okay_for_view(shortcut))
                                check_the_multis(openfile->current);
diff --git a/src/nano.h b/src/nano.h
index b33b7d26..6a456fd0 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -383,6 +383,10 @@ typedef struct openfilestruct {
                /* Whether the file has been modified. */
        struct stat *current_stat;
                /* The file's current stat information. */
+#ifdef ENABLE_WRAPPING
+       linestruct *spillage_line;
+               /* The line for prepending stuff to during automatic 
hard-wrapping. */
+#endif
 #ifndef NANO_TINY
        linestruct *mark;
                /* The line in the file where the mark is set; NULL if not set. 
*/
diff --git a/src/proto.h b/src/proto.h
index 5fb1ca74..2609416b 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -523,7 +523,6 @@ void update_multiline_undo(ssize_t lineno, char 
*indentation);
 void update_undo(undo_type action);
 #endif /* !NANO_TINY */
 #ifdef ENABLE_WRAPPING
-void wrap_reset(void);
 bool do_wrap(void);
 #endif
 #if defined(ENABLE_HELP) || defined(ENABLED_WRAPORJUSTIFY)
diff --git a/src/text.c b/src/text.c
index 7442cee7..90328ebb 100644
--- a/src/text.c
+++ b/src/text.c
@@ -35,11 +35,6 @@
 static pid_t pid_of_command = -1;
                /* The PID of the forked process -- needed when wanting to 
abort it. */
 #endif
-#ifdef ENABLE_WRAPPING
-static bool prepend_wrap = FALSE;
-               /* Should we prepend wrapped text to the next line? */
-#endif
-
 #ifdef ENABLE_WORDCOMPLETION
 static int pletion_x = 0;
                /* The x position in pletion_line of the last found completion. 
*/
@@ -1412,13 +1407,6 @@ void update_undo(undo_type action)
 #endif /* !NANO_TINY */
 
 #ifdef ENABLE_WRAPPING
-/* Unset the prepend_wrap flag.  We need to do this as soon as we do
- * something other than type text. */
-void wrap_reset(void)
-{
-       prepend_wrap = FALSE;
-}
-
 /* When the current line is overlong, hard-wrap it at the furthest possible
  * whitespace character, and (if possible) prepend the remainder of the line
  * to the next line.  Return TRUE if wrapping occurred, and FALSE otherwise. */
@@ -1466,7 +1454,8 @@ bool do_wrap(void)
        /* When prepending and the remainder of this line will not make the next
         * line too long, then join the two lines, so that, after the line wrap,
         * the remainder will effectively have been prefixed to the next line. 
*/
-       if (prepend_wrap && rest_length + strlenpt(line->next->data) <= 
wrap_at) {
+       if (openfile->spillage_line && line->next == openfile->spillage_line &&
+                               rest_length + strlenpt(line->next->data) <= 
wrap_at) {
                /* Go to the end of this line. */
                openfile->current_x = line_len;
 
@@ -1512,13 +1501,11 @@ bool do_wrap(void)
        do_enter();
 
        if (cursor_x < wrap_loc) {
+               openfile->spillage_line = openfile->current;
                openfile->current = openfile->current->prev;
                openfile->current_x = cursor_x;
-               prepend_wrap = TRUE;
-       } else {
+       } else
                openfile->current_x += (cursor_x - wrap_loc);
-               prepend_wrap = FALSE;
-       }
 
        openfile->placewewant = xplustabs();
 
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]