nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH 2/4] options: add --zap, that makes <Bsp> and <Del>


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 2/4] options: add --zap, that makes <Bsp> and <Del> erase a marked region
Date: Sun, 28 Oct 2018 14:41:02 +0100

From: Brand Huntsman <address@hidden>

Using --zap or -Z on the command line, or 'set zap' in a nanorc file,
now makes the <Bsp> and <Del> keys erase selected text (marked region)
as they do in some other editors, and without affecting the cutbuffer.

This fulfills https://savannah.gnu.org/bugs/?54837.
Requested-by: Liu Hao <address@hidden>

Signed-off-by: Brand Huntsman <address@hidden>
---
 doc/nano.texi        |  9 +++++++++
 doc/nanorc.5         |  4 ++++
 doc/sample.nanorc.in |  3 +++
 src/nano.c           |  7 ++++++-
 src/nano.h           |  3 ++-
 src/rcfile.c         |  1 +
 src/text.c           | 10 ++++++++++
 syntax/nanorc.nanorc |  2 +-
 8 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/doc/nano.texi b/doc/nano.texi
index 13495249..3cf71dc3 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -270,6 +270,11 @@ should be considered as parts of words.  This overrides 
option
 Specify the syntax to be used for highlighting.
 @xref{Syntax Highlighting} for more info.
 
address@hidden -Z
address@hidden --zap
+Let an unmodified @key{Backspace} or @key{Delete} erase the marked region
+(instead of a single character and without affecting the cutbuffer).
+
 @item -a
 @itemx --atblanks
 When doing soft line wrapping, wrap lines at whitespace
@@ -932,6 +937,10 @@ Specify which other characters (besides the normal 
alphanumeric ones)
 should be considered as parts of words.  This overrides the option
 @code{wordbounds}.
 
address@hidden set zap
+Let an unmodified @key{Backspace} or @key{Delete} erase the marked region
+(instead of a single character and without affecting the cutbuffer).
+
 @end table
 
 @node Syntax Highlighting
diff --git a/doc/nanorc.5 b/doc/nanorc.5
index a40bcf0a..e8a8532d 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -297,6 +297,10 @@ characters as parts of words.
 Specify which other characters (besides the normal alphanumeric ones)
 should be considered as parts of words.  This overrides the option
 \fBwordbounds\fR.
+.TP
+.B set zap
+Let an unmodified Backspace or Delete erase the marked region
+(instead of a single character and without affecting the cutbuffer).
 
 .SH SYNTAX HIGHLIGHTING
 Coloring the different syntactic elements of a file
diff --git a/doc/sample.nanorc.in b/doc/sample.nanorc.in
index 455a69b7..bc692865 100644
--- a/doc/sample.nanorc.in
+++ b/doc/sample.nanorc.in
@@ -194,6 +194,9 @@
 ## set, it overrides option 'set wordbounds'.
 # set wordchars "<_>."
 
+## Let an unmodified Backspace or Delete erase the marked region (instead
+## of a single character and without affecting the cutbuffer).
+# set zap
 
 ## Paint the interface elements of nano.  These are examples;
 ## by default there are no colors, except for errorcolor.
diff --git a/src/nano.c b/src/nano.c
index 8c42eaa9..1aa8b276 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -851,6 +851,7 @@ void usage(void)
                                        N_("Syntax definition to use for 
coloring"));
 #endif
 #ifndef NANO_TINY
+       print_opt("-Z", "--zap", N_("Let Bsp and Del erase a marked region"));
        print_opt("-a", "--atblanks", N_("When soft-wrapping, do it at 
whitespace"));
 #endif
        print_opt("-c", "--constantshow", N_("Constantly show cursor 
position"));
@@ -2023,6 +2024,7 @@ int main(int argc, char **argv)
                {"smooth", 0, NULL, 'S'},
                {"wordbounds", 0, NULL, 'W'},
                {"wordchars", 1, NULL, 'X'},
+               {"zap", 0, NULL, 'Z'},
                {"atblanks", 0, NULL, 'a'},
                {"autoindent", 0, NULL, 'i'},
                {"cutfromcursor", 0, NULL, 'k'},
@@ -2086,7 +2088,7 @@ int main(int argc, char **argv)
 
        while ((optchr =
                getopt_long(argc, argv,
-                               
"ABC:DEFGHIKLMNOPQ:RST:UVWX:Y:abcdefghijklmno:pqr:s:tuvwxyz$",
+                               
"ABC:DEFGHIKLMNOPQ:RST:UVWX:Y:Zabcdefghijklmno:pqr:s:tuvwxyz$",
                                long_options, NULL)) != -1) {
                switch (optchr) {
 #ifndef NANO_TINY
@@ -2192,6 +2194,9 @@ int main(int argc, char **argv)
                                break;
 #endif
 #ifndef NANO_TINY
+                       case 'Z':
+                               SET(LET_THEM_ZAP);
+                               break;
                        case 'a':
                                SET(AT_BLANKS);
                                break;
diff --git a/src/nano.h b/src/nano.h
index 50937695..70cd353c 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -540,7 +540,8 @@ enum
        LINE_NUMBERS,
        NO_PAUSES,
        AT_BLANKS,
-       AFTER_ENDS
+       AFTER_ENDS,
+       LET_THEM_ZAP
 };
 
 /* Flags for the menus in which a given function should be present. */
diff --git a/src/rcfile.c b/src/rcfile.c
index d8a2d1fe..5ed715c9 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -112,6 +112,7 @@ static const rcoption rcopts[] = {
        {"whitespace", 0},
        {"wordbounds", WORD_BOUNDS},
        {"wordchars", 0},
+       {"zap", LET_THEM_ZAP},
 #endif
 #ifdef ENABLE_COLOR
        {"titlecolor", 0},
diff --git a/src/text.c b/src/text.c
index c9fb4868..abdd243d 100644
--- a/src/text.c
+++ b/src/text.c
@@ -183,6 +183,11 @@ void do_deletion(undo_type action)
 /* Delete the character under the cursor. */
 void do_delete(void)
 {
+#ifndef NANO_TINY
+       if (openfile->mark && ISSET(LET_THEM_ZAP))
+               zap_text();
+       else
+#endif
        do_deletion(DEL);
 }
 
@@ -190,6 +195,11 @@ void do_delete(void)
  * character, and then delete the character under the cursor. */
 void do_backspace(void)
 {
+#ifndef NANO_TINY
+       if (openfile->mark && ISSET(LET_THEM_ZAP))
+               zap_text();
+       else
+#endif
        if (openfile->current != openfile->fileage || openfile->current_x > 0) {
                do_left();
                do_deletion(BACK);
diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc
index 1ca8b913..976396aa 100644
--- a/syntax/nanorc.nanorc
+++ b/syntax/nanorc.nanorc
@@ -7,7 +7,7 @@ comment "#"
 icolor brightred 
"^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment|linter|i?color|extendsyntax).*$"
 
 # Keywords
-icolor brightgreen 
"^[[:space:]]*(set|unset)[[:space:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|trimblanks|unix|view|wordbounds)\>"
+icolor brightgreen 
"^[[:space:]]*(set|unset)[[:space:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|trimblanks|unix|view|wordbounds|zap)\>"
 icolor yellow 
"^[[:space:]]*set[[:space:]]+((error|function|key|number|selected|status|title)color)[[:space:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan|normal)?(,(white|black|red|blue|green|yellow|magenta|cyan|normal))?\>"
 icolor brightgreen 
"^[[:space:]]*set[[:space:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|selectedcolor|speller|statuscolor|titlecolor|whitespace|wordchars)[[:space:]]+"
 icolor brightgreen 
"^[[:space:]]*bind[[:space:]]+((\^([[:alpha:]]|address@hidden|Space)|M-([[:alpha:]]|[]!"#$%&'()*+,./0-9:;<=>address@hidden|}~-]|Space))|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+([[:alpha:]]+|".*")[[:space:]]+(all|main|search|replace(with)?|yesno|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)"
-- 
2.19.1




reply via email to

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