>From fc57cfab1e0bff66c680d56dc9f381031da463dc Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Thu, 18 Oct 2018 21:47:23 -0600 Subject: [PATCH 2/3] zap selection with Bsp/Del keys when enabled with zap nanorc toggle, -Z or --zap Signed-off-by: Brand Huntsman --- doc/nano.texi | 7 +++++++ doc/nanorc.5 | 3 +++ doc/sample.nanorc.in | 2 ++ src/nano.c | 8 +++++++- src/nano.h | 1 + src/rcfile.c | 1 + src/text.c | 10 ++++++++++ syntax/nanorc.nanorc | 2 +- 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/doc/nano.texi b/doc/nano.texi index 0c968838..431a5644 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -270,6 +270,10 @@ 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 +Zap marked region with unmodified backspace or delete keys. + @item -a @itemx --atblanks When doing soft line wrapping, wrap lines at whitespace @@ -928,6 +932,9 @@ 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 +Zap marked region with unmodified backspace or delete keys. + @end table @node Syntax Highlighting diff --git a/doc/nanorc.5 b/doc/nanorc.5 index d6e35c94..47f87259 100644 --- a/doc/nanorc.5 +++ b/doc/nanorc.5 @@ -295,6 +295,9 @@ 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 +Zap marked region with unmodified backspace or delete keys. .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..be3592e5 100644 --- a/doc/sample.nanorc.in +++ b/doc/sample.nanorc.in @@ -194,6 +194,8 @@ ## set, it overrides option 'set wordbounds'. # set wordchars "<_>." +## Zap marked region with unmodified backspace or delete keys. +# 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 2d0458ce..1fdfcef3 100644 --- a/src/nano.c +++ b/src/nano.c @@ -851,6 +851,8 @@ void usage(void) N_("Syntax definition to use for coloring")); #endif #ifndef NANO_TINY + print_opt("-Z", "--zap", + N_("Zap marked region with unmodified backspace or delete keys")); print_opt("-a", "--atblanks", N_("When soft-wrapping, do it at whitespace")); #endif print_opt("-c", "--constantshow", N_("Constantly show cursor position")); @@ -2023,6 +2025,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 +2089,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 +2195,9 @@ int main(int argc, char **argv) break; #endif #ifndef NANO_TINY + case 'Z': + SET(ZAP_BSP_DEL); + break; case 'a': SET(AT_BLANKS); break; diff --git a/src/nano.h b/src/nano.h index 874b2407..1b3802ae 100644 --- a/src/nano.h +++ b/src/nano.h @@ -530,6 +530,7 @@ enum TABS_TO_SPACES, QUICK_BLANK, WORD_BOUNDS, + ZAP_BSP_DEL, NO_NEWLINES, BOLD_TEXT, QUIET, diff --git a/src/rcfile.c b/src/rcfile.c index d8a2d1fe..f5f5c0ab 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", ZAP_BSP_DEL}, #endif #ifdef ENABLE_COLOR {"titlecolor", 0}, diff --git a/src/text.c b/src/text.c index d1226095..c9f90a2c 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 (ISSET(ZAP_BSP_DEL) && openfile->mark) + do_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 (ISSET(ZAP_BSP_DEL) && openfile->mark) + do_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.18.1