[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Nano-devel] [PATCH 7/7] wrapping: when autoindenting, use indentation o
From: |
Benno Schulenberg |
Subject: |
[Nano-devel] [PATCH 7/7] wrapping: when autoindenting, use indentation of next line as example |
Date: |
Tue, 22 May 2018 21:21:55 +0200 |
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 34bf6021..eca097a0 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;
--
2.17.0
- [Nano-devel] [PATCH 7/7] wrapping: when autoindenting, use indentation of next line as example,
Benno Schulenberg <=