From d00ab406bc2d8bb4f23c6a63d610e04c57fe57f0 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 22 May 2018 21:10:10 +0200 Subject: [PATCH] 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. --- src/text.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/text.c b/src/text.c index 48ed07cc..fb94d69e 100644 --- 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;