From 66fd6a5ab10430f93d8bc87c7efae0b533188f74 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Sat, 2 Dec 2017 14:02:26 +0100
Subject: [PATCH] options: rename 'justifytrim' to 'trimblanks', because it has
 morphed

The option now causes nano to trim trailing whitespace also when
hardwrapping occurs while the user is typing.
---
 doc/nano.texi        | 7 ++++---
 doc/nanorc.5         | 7 ++++---
 doc/sample.nanorc.in | 6 +++---
 src/nano.h           | 2 +-
 src/rcfile.c         | 3 ++-
 src/text.c           | 4 ++--
 syntax/nanorc.nanorc | 2 +-
 7 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/doc/nano.texi b/doc/nano.texi
index ac614911..ac68b4b2 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -753,9 +753,6 @@ And either @var{fgcolor} or ,@var{bgcolor} may be left out.
 Save the last hundred search strings and replacement strings and
 executed commands, so they can be easily reused in later sessions.
 
-@item set justifytrim
-When justifying text, trailing whitespace will automatically be removed.
-
 @item set keycolor @var{fgcolor},@var{bgcolor}
 Use this color combination for the shortcut key combos
 in the two help lines at the bottom of the screen.
@@ -899,6 +896,10 @@ Save automatically on exit, don't prompt.
 Use this color combination for the title bar.
 @xref{@code{set functioncolor}} for valid color names.
 
+@item set trimblanks
+Remove trailing whitespace from wrapped lines when automatic
+hard-wrapping occurs or when text is justified.
+
 @item set unix
 Save a file by default in Unix format.  This overrides nano's
 default behavior of saving a file in the format that it had.
diff --git a/doc/nanorc.5 b/doc/nanorc.5
index 25277a5e..1b05a287 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -118,9 +118,6 @@ See \fBset titlecolor\fR for more details.
 Save the last hundred search strings and replacement strings and
 executed commands, so they can be easily reused in later sessions.
 .TP
-.B set justifytrim
-When justifying text, trailing whitespace will automatically be removed.
-.TP
 .B set keycolor \fIfgcolor\fR,\fIbgcolor\fR
 Specify the color combination to use for the shortcut key combos
 in the two help lines at the bottom of the screen.
@@ -269,6 +266,10 @@ Valid names for the foreground and background colors are:
 The name of the foreground color may be prefixed with \fBbright\fR.
 And either "\fIfgcolor\fR" or ",\fIbgcolor\fR" may be left out.
 .TP
+.B set trimblanks
+Remove trailing whitespace from wrapped lines when automatic
+hard-wrapping occurs or when text is justified.
+.TP
 .B set unix
 Save a file by default in Unix format.  This overrides nano's
 default behavior of saving a file in the format that it had.
diff --git a/doc/sample.nanorc.in b/doc/sample.nanorc.in
index 7f6218c5..77744ba5 100644
--- a/doc/sample.nanorc.in
+++ b/doc/sample.nanorc.in
@@ -57,9 +57,6 @@
 ## Remember the used search/replace strings for the next session.
 # set historylog
 
-## Make the justify command kill whitespace at the end of lines.
-# set justifytrim
-
 ## Display line numbers to the left of the text.
 # set linenumbers
 
@@ -175,6 +172,9 @@
 ## Save automatically on exit; don't prompt.
 # set tempfile
 
+## Snip whitespace at the end of lines when justifying or hard-wrapping.
+# set trimblanks
+
 ## Disallow file modification.  Why would you want this in an rcfile? ;)
 # set view
 
diff --git a/src/nano.h b/src/nano.h
index 3343b9a4..7ce36646 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -527,7 +527,7 @@ enum
     LOCKING,
     NOREAD_MODE,
     MAKE_IT_UNIX,
-    JUSTIFY_TRIM,
+    TRIM_BLANKS,
     SHOW_CURSOR,
     LINE_NUMBERS,
     NO_PAUSES,
diff --git a/src/rcfile.c b/src/rcfile.c
index 7a619c31..6d543315 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -96,7 +96,7 @@ static const rcoption rcopts[] = {
     {"casesensitive", CASE_SENSITIVE},
     {"cut", CUT_FROM_CURSOR},  /* deprecated form, remove in 2020 */
     {"cutfromcursor", CUT_FROM_CURSOR},
-    {"justifytrim", JUSTIFY_TRIM},
+    {"justifytrim", TRIM_BLANKS},  /* deprecated form, remove in 2020 */
     {"locking", LOCKING},
     {"matchbrackets", 0},
     {"noconvert", NO_CONVERT},
@@ -106,6 +106,7 @@ static const rcoption rcopts[] = {
     {"smooth", SMOOTH_SCROLL},
     {"softwrap", SOFTWRAP},
     {"tabstospaces", TABS_TO_SPACES},
+    {"trimblanks", TRIM_BLANKS},
     {"unix", MAKE_IT_UNIX},
     {"whitespace", 0},
     {"wordbounds", WORD_BOUNDS},
diff --git a/src/text.c b/src/text.c
index b1b1727c..b5ba75e6 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1642,7 +1642,7 @@ bool do_wrap(filestruct *line)
     openfile->current_x = wrap_loc;
 
     /* When requested, snip trailing blanks off the wrapped line. */
-    if (ISSET(JUSTIFY_TRIM)) {
+    if (ISSET(TRIM_BLANKS)) {
 	size_t cur_x = move_mbleft(line->data, wrap_loc);
 
 	while (is_blank_mbchar(line->data + cur_x)) {
@@ -2414,7 +2414,7 @@ void do_justify(bool full_justify)
 	    }
 #endif
 	    /* When requested, snip all trailing blanks. */
-	    if (ISSET(JUSTIFY_TRIM)) {
+	    if (ISSET(TRIM_BLANKS)) {
 		while (break_pos > 0 &&
 			is_blank_mbchar(&openfile->current->data[break_pos - 1])) {
 		    break_pos--;
diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc
index 89153eda..9882d6b0 100644
--- a/syntax/nanorc.nanorc
+++ b/syntax/nanorc.nanorc
@@ -7,7 +7,7 @@ comment "#"
 icolor brightred "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment|linter|formatter|i?color|extendsyntax).*$"
 
 # Keywords
-icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|justifytrim|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|unix|view|wordbounds)\>"
+icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|trimblanks|unix|view|wordbounds)\>"
 icolor yellow "^[[:space:]]*set[[:space:]]+((function|key|number|selected|status|title)color)[[:space:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>"
 icolor brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|selectedcolor|speller|statuscolor|titlecolor|whitespace|wordchars)[[:space:]]+"
 icolor brightgreen "^[[:space:]]*bind[[:space:]]+((\^([[:alpha:]]|[]0-9\^_]|Space)|M-([[:alpha:]]|[]!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+[[:alpha:]]+[[:space:]]+(all|main|search|replace(with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)"
-- 
GitLab