nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit d00ab406bc2d8bb4f23c6a63d610e04c57fe57f0
parent d63d79b0679e94d92803eb0ece84befa1705ad24
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 22 May 2018 21:10:10 +0200

wrapping: when autoindenting, use indentation of next line as example

When doing autoindentation, and the next line is not the start of
a new paragraph, then use the indentation of that line for the new
line, as it is more likely to have the desired indentation -- the
current line might be the start of the paragraph and thus could
have a deviant indentation.

Diffstat:
Msrc/text.c | 13++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/text.c b/src/text.c @@ -1026,12 +1026,19 @@ void do_redo(void) void do_enter(void) { filestruct *newnode = make_new_node(openfile->current); + filestruct *sampleline = openfile->current; size_t extra = 0; #ifndef NANO_TINY bool allblanks = FALSE; if (ISSET(AUTOINDENT)) { - extra = indent_length(openfile->current->data); + /* If the next line is in this same paragraph, use its indentation + * as the model, as it is more likely to be what the user wants. */ + if (openfile->current->next && inpar(openfile->current->next) && + !begpar(openfile->current->next)) + sampleline = openfile->current->next; + + extra = indent_length(sampleline->data); /* If we are breaking the line in the indentation, limit the new * indentation to the current x position. */ @@ -1047,8 +1054,8 @@ void do_enter(void) openfile->current_x); #ifndef NANO_TINY if (ISSET(AUTOINDENT)) { - /* Copy the whitespace from the current line to the new one. */ - strncpy(newnode->data, openfile->current->data, extra); + /* Copy the whitespace from the sample line to the new one. */ + strncpy(newnode->data, sampleline->data, extra); /* If there were only blanks before the cursor, trim them. */ if (allblanks) openfile->current_x = 0;