From a0055f3640483992c6a3f95eb9301f8d3e6f0d83 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 16 Dec 2019 13:44:44 +0100 Subject: [PATCH] wrapping: never break in the quoting part nor in the indentation part MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rationale: nano should not wrap inside the quoting part of a line because it would change the quoting level, which would misrepresent things, nor should it wrap inside the indentation part because when the user tries to indent something beyond the target wrapping width, she/he does not intend to create a line containing only whitespace, but effectively wants to push the text beyond the wrapping width. This copies the behavior of the rewrap_paragraph() routine that is used during justification, so that automatic hard-wrapping ends up with the same result as justifying. Also, always do automatic hard-wrapping when --breaklonglines is in effect, also when --autoindent is active. This fixes https://savannah.gnu.org/bugs/?57425. The bug was old -- it existed since at least version 2.0.6. This furthermore avoids https://savannah.gnu.org/bugs/?57422. Reported-by: Sébastien Desreux That bug existed since version 4.4, commit 8fce33af. --- src/text.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/text.c b/src/text.c index 0896506a..4f759db0 100644 --- a/src/text.c +++ b/src/text.c @@ -1405,6 +1405,8 @@ bool do_wrap(void) /* The line to be wrapped, if needed and possible. */ size_t line_len = strlen(line->data); /* The length of this line. */ + size_t pre_len = quote_length(line->data); + /* The length of the leading quoting, plus later also indentation. */ size_t cursor_x = openfile->current_x; /* The current cursor position, for comparison with the wrap point. */ ssize_t wrap_loc; @@ -1414,25 +1416,24 @@ bool do_wrap(void) size_t rest_length; /* The length of the remainder. */ + pre_len += indent_length(line->data + pre_len); + /* First find the last blank character where we can break the line. */ - wrap_loc = break_line(line->data, wrap_at, FALSE); + wrap_loc = break_line(line->data + pre_len, + wrap_at - wideness(line->data, pre_len), FALSE); /* If no wrapping point was found before end-of-line, we don't wrap. */ - if (wrap_loc == -1 || line->data[wrap_loc] == '\0') + if (wrap_loc == -1 || wrap_loc + pre_len == line_len) return FALSE; /* Step forward to the character just after the blank. */ - wrap_loc = step_right(line->data, wrap_loc); + wrap_loc = step_right(line->data + pre_len, wrap_loc) + pre_len; /* When now at end-of-line, no need to wrap. */ if (line->data[wrap_loc] == '\0') return FALSE; #ifndef NANO_TINY - /* When autoindenting, we don't wrap right after the indentation. */ - if (ISSET(AUTOINDENT) && wrap_loc == indent_length(line->data)) - return FALSE; - add_undo(SPLIT_BEGIN, NULL); #endif #ifdef ENABLE_JUSTIFY