nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] input: do not auto-indent when something is pasted into nano


From: Benno Schulenberg
Subject: [PATCH 2/2] input: do not auto-indent when something is pasted into nano from outside
Date: Sun, 5 Jan 2020 16:32:07 +0100

Also, do not break overlong lines and do not convert tabs to spaces.
In other words: accept an outside paste as literally as possible.

This fulfills https://savannah.gnu.org/bugs/?40060.
Requested-by: Egmont Koblinger <address@hidden>

And fulfills https://savannah.gnu.org/bugs/?57527.
Requested-by: Sébastien Desreux <address@hidden>
Requested-by: Hans Ecke <address@hidden>
---
 src/nano.c | 9 ++++++++-
 src/text.c | 6 +++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index 557a1903..5368d751 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -78,6 +78,9 @@ static linestruct *hindline;
 static linestruct *filetail;
                /* What was the bottom line of the buffer. */
 
+static bool pasting_from_outside = FALSE;
+               /* Whether a bracketed paste is in progress. */
+
 /* Create a new linestruct node.  Note that we do not set prevnode->next. */
 linestruct *make_new_node(linestruct *prevnode)
 {
@@ -1676,6 +1679,9 @@ void do_input(void)
        }
 #endif
 
+       if (bracketed_paste)
+               pasting_from_outside = TRUE;
+
        /* Check for a shortcut in the main list. */
        shortcut = get_shortcut(&input);
 
@@ -1717,6 +1723,7 @@ void do_input(void)
                         * at once, filtering out any low control codes. */
                        puddle[depth] = '\0';
                        do_output(puddle, depth, FALSE);
+                       pasting_from_outside = FALSE;
 
                        /* Empty the input buffer. */
                        free(puddle);
@@ -1883,7 +1890,7 @@ void do_output(char *output, size_t output_len, bool 
allow_cntrls)
 
 #ifdef ENABLE_WRAPPING
                /* If text gets wrapped, the edit window needs a refresh. */
-               if (ISSET(BREAK_LONG_LINES) && do_wrap())
+               if (ISSET(BREAK_LONG_LINES) && !pasting_from_outside && 
do_wrap())
                        refresh_needed = TRUE;
 #endif
        }
diff --git a/src/text.c b/src/text.c
index 118d9994..7a31c510 100644
--- a/src/text.c
+++ b/src/text.c
@@ -73,7 +73,7 @@ void do_tab(void)
        else
 #endif
 #ifndef NANO_TINY
-       if (ISSET(TABS_TO_SPACES)) {
+       if (ISSET(TABS_TO_SPACES) && !bracketed_paste) {
                char *spaces = charalloc(tabsize + 1);
                size_t length = tabsize - (xplustabs() % tabsize);
 
@@ -853,7 +853,7 @@ void do_enter(void)
        linestruct *sampleline = openfile->current;
        bool allblanks = FALSE;
 
-       if (ISSET(AUTOINDENT)) {
+       if (ISSET(AUTOINDENT) && !bracketed_paste) {
 #ifdef ENABLE_JUSTIFY
                /* When doing automatic long-line wrapping and the next line is
                 * in this same paragraph, use its indentation as the model. */
@@ -875,7 +875,7 @@ void do_enter(void)
        strcpy(&newnode->data[extra], openfile->current->data +
                                                                                
openfile->current_x);
 #ifndef NANO_TINY
-       if (ISSET(AUTOINDENT)) {
+       if (ISSET(AUTOINDENT) && !bracketed_paste) {
                /* 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. */
-- 
2.24.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]