options: add --zap, that makes <Bsp> and <Del> erase a marked region

Using --zap or -Z on the command line, or 'set zap' in a nanorc file,
makes the <Bsp> and <Del> keys erase selected text (a 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 <lh_mouse@126.com>

Signed-off-by: Brand Huntsman <alpha@qzx.com>
master
Brand Huntsman 2018-10-24 03:02:08 -06:00 committed by Benno Schulenberg
parent 5662a38802
commit ae3ec1784d
9 changed files with 40 additions and 3 deletions

View File

@ -167,6 +167,10 @@ should be considered as part of a word. This overrides option
Specify the name of the syntax highlighting to use from among the ones
defined in the \fInanorc\fP files.
.TP
.BR \-Z ", " \-\-zap
Let an unmodified Backspace or Delete erase the marked region
(instead of a single character, and without affecting the cutbuffer).
.TP
.BR \-a ", " \-\-atblanks
When doing soft line wrapping, wrap lines at whitespace
instead of always at the edge of the screen.

View File

@ -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.
@item -Z
@itemx --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}.
@item 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

View File

@ -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

View File

@ -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.

View File

@ -845,6 +845,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"));
@ -2020,6 +2021,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'},
@ -2083,7 +2085,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
@ -2189,6 +2191,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;

View File

@ -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. */

View File

@ -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},

View File

@ -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);

View File

@ -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:]]|[]@\^_]|Space)|M-([[:alpha:]]|[]!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|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:]]*$)"