nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH 1/2] wrapping: delete trailing blanks upon hardwrapp


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 1/2] wrapping: delete trailing blanks upon hardwrapping, when requested
Date: Sat, 2 Dec 2017 14:08:57 +0100

This fulfills https://savannah.gnu.org/bugs/?52198.
---
 src/text.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/text.c b/src/text.c
index e89507fe..b6f2728e 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1619,7 +1619,7 @@ bool do_wrap(filestruct *line)
 
        /* If after_break doesn't end in a blank, make sure it ends in a
         * space. */
-       if (!is_blank_mbchar(end) && !ISSET(JUSTIFY_TRIM)) {
+       if (!is_blank_mbchar(end)) {
 #ifndef NANO_TINY
            add_undo(ADD);
 #endif
@@ -1649,8 +1649,21 @@ bool do_wrap(filestruct *line)
        }
     }
 
-    /* Go to the wrap location and split the line there. */
+    /* Go to the wrap location. */
     openfile->current_x = wrap_loc;
+
+    /* When requested, snip trailing blanks off the wrapped line. */
+    if (ISSET(JUSTIFY_TRIM)) {
+       size_t cur_x = move_mbleft(line->data, wrap_loc);
+
+       while (is_blank_mbchar(line->data + cur_x) && cur_x > 0) {
+           openfile->current_x = cur_x;
+           do_delete();
+           cur_x = move_mbleft(line->data, cur_x);
+       }
+    }
+
+    /* Now split the line. */
     do_enter();
 
     if (old_x < wrap_loc) {
-- 
2.14.3




reply via email to

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