Discussion:
[Nano-devel] [PATCH 1/4] new feature: a bindable 'zap', to erase text without changing cutbuffer
Benno Schulenberg
2018-10-28 13:41:01 UTC
Permalink
From: Brand Huntsman <***@qzx.com>

Signed-off-by: Brand Huntsman <***@qzx.com>
---
doc/nano.texi | 3 +++
doc/nanorc.5 | 3 +++
src/cut.c | 41 ++++++++++++++++++++++++++++++++++-------
src/files.c | 4 ++--
src/global.c | 8 ++++++++
src/nano.h | 2 +-
src/proto.h | 3 ++-
src/text.c | 24 +++++++++++++++++++-----
8 files changed, 72 insertions(+), 16 deletions(-)

diff --git a/doc/nano.texi b/doc/nano.texi
index a643ec80..13495249 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -1150,6 +1150,9 @@ Pastes the currently stored text into the current buffer at the
current cursor position.
(The old form 'uncut' is deprecated.)

+@item zap
+Throw away the current line (or the marked region).
+
@item cutwordleft
Cuts from the cursor position to the beginning of the preceding word.
(This function is not bound by default. If your terminal produces
diff --git a/doc/nanorc.5 b/doc/nanorc.5
index 96e49df6..a40bcf0a 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -506,6 +506,9 @@ Pastes the currently stored text into the current buffer at the
current cursor position.
(The old form 'uncut' is deprecated.)
.TP
+.B zap
+Throw away the current line (or the marked region).
+.TP
.B cutwordleft
Cuts from the cursor position to the beginning of the preceding word.
(This function is not bound by default. If your terminal produces
diff --git a/src/cut.c b/src/cut.c
index 69c50062..0f33e1d4 100644
--- a/src/cut.c
+++ b/src/cut.c
@@ -104,8 +104,9 @@ void cut_to_eof(void)
/* Move text from the current buffer into the cutbuffer. If
* copy_text is TRUE, copy the text back into the buffer afterward.
* If cut_till_eof is TRUE, move all text from the current cursor
- * position to the end of the file into the cutbuffer. */
-void do_cut_text(bool copy_text, bool marked, bool cut_till_eof)
+ * position to the end of the file into the cutbuffer. If append
+ * is TRUE (when zapping), always append the cut to the cutbuffer. */
+void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append)
{
#ifndef NANO_TINY
filestruct *cb_save = NULL;
@@ -120,7 +121,7 @@ void do_cut_text(bool copy_text, bool marked, bool cut_till_eof)
size_t was_totsize = openfile->totsize;

/* If cuts were not continuous, or when cutting a region, clear the slate. */
- if (!keep_cutbuffer || marked || cut_till_eof) {
+ if (!append && (!keep_cutbuffer || marked || cut_till_eof)) {
free_filestruct(cutbuffer);
cutbuffer = NULL;
/* After a line cut, future line cuts should add to the cutbuffer. */
@@ -193,10 +194,10 @@ void do_cut_text_void(void)
openfile->current_undo->mark_begin_lineno != openfile->current->lineno ||
!keep_cutbuffer)
add_undo(CUT);
- do_cut_text(FALSE, openfile->mark, FALSE);
+ do_cut_text(FALSE, openfile->mark, FALSE, FALSE);
update_undo(CUT);
#else
- do_cut_text(FALSE, FALSE, FALSE);
+ do_cut_text(FALSE, FALSE, FALSE, FALSE);
#endif
}

@@ -218,7 +219,7 @@ void do_copy_text(void)
if (mark_is_set || openfile->current != next_contiguous_line)
cutbuffer_reset();

- do_cut_text(TRUE, mark_is_set, FALSE);
+ do_cut_text(TRUE, mark_is_set, FALSE, FALSE);

/* If the mark was set, blow away the cutbuffer on the next copy. */
next_contiguous_line = (mark_is_set ? NULL : openfile->current);
@@ -236,9 +237,35 @@ void do_copy_text(void)
void do_cut_till_eof(void)
{
add_undo(CUT_TO_EOF);
- do_cut_text(FALSE, FALSE, TRUE);
+ do_cut_text(FALSE, FALSE, TRUE, FALSE);
update_undo(CUT_TO_EOF);
}
+
+/* Erase text (current line or marked region), sending it into oblivion. */
+void zap_text(void)
+{
+ /* Remember the current cutbuffer so it can be restored after the zap. */
+ filestruct *was_cutbuffer = cutbuffer;
+ filestruct *was_cutbottom = cutbottom;
+
+ /* Add a new undo item only when the current item is not a ZAP or when
+ * the current zap is not contiguous with the previous zapping. */
+ if (openfile->last_action != ZAP || openfile->current_undo == NULL ||
+ openfile->current_undo->mark_begin_lineno != openfile->current->lineno ||
+ openfile->current_undo->xflags & (MARK_WAS_SET|WAS_MARKED_FORWARD))
+ add_undo(ZAP);
+
+ /* Use the cutbuffer from the ZAP undo item, so the cut can be undone. */
+ cutbuffer = openfile->current_undo->cutbuffer;
+ cutbottom = openfile->current_undo->cutbottom;
+
+ do_cut_text(FALSE, openfile->mark, FALSE, TRUE);
+
+ update_undo(ZAP);
+
+ cutbuffer = was_cutbuffer;
+ cutbottom = was_cutbottom;
+}
#endif /* !NANO_TINY */

/* Copy text from the cutbuffer into the current buffer. */
diff --git a/src/files.c b/src/files.c
index 5878ff00..4b757c65 100644
--- a/src/files.c
+++ b/src/files.c
@@ -533,7 +533,7 @@ void replace_buffer(const char *filename)
#ifndef NANO_TINY
add_undo(CUT_TO_EOF);
#endif
- do_cut_text(FALSE, FALSE, TRUE);
+ do_cut_text(FALSE, FALSE, TRUE, FALSE);
#ifndef NANO_TINY
update_undo(CUT_TO_EOF);
#endif
@@ -574,7 +574,7 @@ void replace_marked_buffer(const char *filename)
/* Throw away the text under the mark. */
cutbuffer = NULL;
add_undo(CUT);
- do_cut_text(FALSE, TRUE, FALSE);
+ do_cut_text(FALSE, TRUE, FALSE, FALSE);
update_undo(CUT);
free_filestruct(cutbuffer);
cutbuffer = was_cutbuffer;
diff --git a/src/global.c b/src/global.c
index e1d7930f..89df838b 100644
--- a/src/global.c
+++ b/src/global.c
@@ -576,6 +576,7 @@ void shortcut_init(void)
const char *mark_gist = N_("Mark text starting from the cursor position");
const char *copy_gist =
N_("Copy current line (or marked region) and store it in cutbuffer");
+ const char *zap_gist = N_("Throw away the current line (or marked region)");
const char *indent_gist = N_("Indent the current line (or marked lines)");
const char *unindent_gist = N_("Unindent the current line (or marked lines)");
const char *undo_gist = N_("Undo the last operation");
@@ -997,6 +998,11 @@ void shortcut_init(void)
N_("Save"), WITHORSANS(savefile_gist), BLANKAFTER, NOVIEW);
#endif

+#ifndef NANO_TINY
+ add_to_funcs(zap_text, MMAIN,
+ N_("Zap Text"), WITHORSANS(zap_gist), BLANKAFTER, NOVIEW);
+#endif
+
#ifndef ENABLE_JUSTIFY
add_to_funcs(flip_goto, MWHEREIS,
N_("Go To Line"), WITHORSANS(gotoline_gist), BLANKAFTER, VIEW);
@@ -1471,6 +1477,8 @@ sc *strtosc(const char *input)
else if (!strcasecmp(input, "copy") ||
!strcasecmp(input, "copytext")) /* Deprecated. Remove end of 2018. */
s->func = do_copy_text;
+ else if (!strcasecmp(input, "zap"))
+ s->func = zap_text;
else if (!strcasecmp(input, "mark"))
s->func = do_mark;
#endif
diff --git a/src/nano.h b/src/nano.h
index 3007881d..50937695 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -178,7 +178,7 @@ typedef enum {
#ifdef ENABLE_COMMENT
COMMENT, UNCOMMENT, PREFLIGHT,
#endif
- CUT, CUT_TO_EOF, PASTE, INSERT, COUPLE_BEGIN, COUPLE_END, OTHER
+ ZAP, CUT, CUT_TO_EOF, PASTE, INSERT, COUPLE_BEGIN, COUPLE_END, OTHER
} undo_type;

/* Structure types. */
diff --git a/src/proto.h b/src/proto.h
index a157ece0..a2834606 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -249,11 +249,12 @@ void cutbuffer_reset(void);
#ifndef NANO_TINY
void cut_marked(bool *right_side_up);
#endif
-void do_cut_text(bool copy_text, bool marked, bool cut_till_eof);
+void do_cut_text(bool copy_text, bool marked, bool cut_till_eof, bool append);
void do_cut_text_void(void);
#ifndef NANO_TINY
void do_copy_text(void);
void do_cut_till_eof(void);
+void zap_text(void);
#endif
void do_uncut_text(void);

diff --git a/src/text.c b/src/text.c
index 8302c7dd..c9fb4868 100644
--- a/src/text.c
+++ b/src/text.c
@@ -687,7 +687,7 @@ void redo_cut(undo *u)
openfile->mark = fsfromline(u->mark_begin_lineno);
openfile->mark_x = (u->xflags == WAS_WHOLE_LINE) ? 0 : u->mark_begin_x;

- do_cut_text(FALSE, TRUE, FALSE);
+ do_cut_text(FALSE, TRUE, FALSE, u->type == ZAP);

free_filestruct(cutbuffer);
cutbuffer = oldcutbuffer;
@@ -792,6 +792,10 @@ void do_undo(void)
undidmsg = _("text add");
break;
#endif
+ case ZAP:
+ undidmsg = _("erasure");
+ undo_cut(u);
+ break;
case CUT_TO_EOF:
case CUT:
undidmsg = _("text cut");
@@ -968,6 +972,10 @@ void do_redo(void)
redidmsg = _("text add");
break;
#endif
+ case ZAP:
+ redidmsg = _("erasure");
+ redo_cut(u);
+ break;
case CUT_TO_EOF:
case CUT:
redidmsg = _("text cut");
@@ -1201,7 +1209,7 @@ bool execute_command(const char *command)
if (ISSET(MULTIBUFFER)) {
switch_to_prev_buffer();
if (openfile->mark)
- do_cut_text(TRUE, TRUE, FALSE);
+ do_cut_text(TRUE, TRUE, FALSE, FALSE);
} else
#endif
{
@@ -1212,7 +1220,7 @@ bool execute_command(const char *command)
openfile->current_x = 0;
}
add_undo(CUT);
- do_cut_text(FALSE, openfile->mark, openfile->mark == NULL);
+ do_cut_text(FALSE, openfile->mark, openfile->mark == NULL, FALSE);
update_undo(CUT);
}

@@ -1403,6 +1411,7 @@ void add_undo(undo_type action)
#endif
case CUT_TO_EOF:
break;
+ case ZAP:
case CUT:
if (openfile->mark) {
u->mark_begin_lineno = openfile->mark->lineno;
@@ -1529,12 +1538,17 @@ void update_undo(undo_type action)
case SPLIT_END:
break;
#endif
+ case ZAP:
case CUT_TO_EOF:
case CUT:
if (!cutbuffer)
break;
- free_filestruct(u->cutbuffer);
- u->cutbuffer = copy_filestruct(cutbuffer);
+ if (u->type == ZAP)
+ u->cutbuffer = cutbuffer;
+ else {
+ free_filestruct(u->cutbuffer);
+ u->cutbuffer = copy_filestruct(cutbuffer);
+ }
if (u->xflags == MARK_WAS_SET) {
/* If the "marking" operation was from right-->left or
* bottom-->top, then swap the mark points. */
--
2.19.1
Benno Schulenberg
2018-10-28 13:41:02 UTC
Permalink
From: Brand Huntsman <***@qzx.com>

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 <***@126.com>

Signed-off-by: Brand Huntsman <***@qzx.com>
---
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.

+@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
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:]]|[]@\^_]|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:]]*$)"
--
2.19.1
Benno Schulenberg
2018-10-28 13:41:03 UTC
Permalink
From: Brand Huntsman <***@qzx.com>

Signed-off-by: Brand Huntsman <***@qzx.com>
---
doc/nano.texi | 1 +
doc/nanorc.5 | 1 +
src/global.c | 2 ++
src/nano.c | 1 +
src/nano.h | 1 +
src/proto.h | 1 +
src/winio.c | 14 ++++++++++++--
7 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/doc/nano.texi b/doc/nano.texi
index 3cf71dc3..606d7cd8 100644
--- a/doc/nano.texi
+++ b/doc/nano.texi
@@ -1161,6 +1161,7 @@ current cursor position.

@item zap
Throw away the current line (or the marked region).
+(This function is bound by default to <Meta+Delete>.)

@item cutwordleft
Cuts from the cursor position to the beginning of the preceding word.
diff --git a/doc/nanorc.5 b/doc/nanorc.5
index e8a8532d..c441260e 100644
--- a/doc/nanorc.5
+++ b/doc/nanorc.5
@@ -512,6 +512,7 @@ current cursor position.
.TP
.B zap
Throw away the current line (or the marked region).
+(This function is bound by default to <Meta+Delete>.)
.TP
.B cutwordleft
Cuts from the cursor position to the beginning of the preceding word.
diff --git a/src/global.c b/src/global.c
index 89df838b..950c0fb9 100644
--- a/src/global.c
+++ b/src/global.c
@@ -76,6 +76,7 @@ int shiftleft, shiftright, shiftup, shiftdown;
int shiftcontrolleft, shiftcontrolright, shiftcontrolup, shiftcontroldown;
int shiftcontrolhome, shiftcontrolend;
int altleft, altright, altup, altdown;
+int altdelete;
int shiftaltleft, shiftaltright, shiftaltup, shiftaltdown;
#endif

@@ -1158,6 +1159,7 @@ void shortcut_init(void)
add_to_sclist(MMAIN, "M-E", 0, do_redo, 0);
add_to_sclist(MMAIN, "Sh-^Del", CONTROL_SHIFT_DELETE, do_cut_prev_word, 0);
add_to_sclist(MMAIN, "^Del", CONTROL_DELETE, do_cut_next_word, 0);
+ add_to_sclist(MMAIN, "M-Del", ALT_DELETE, zap_text, 0);
#endif
#ifdef ENABLE_WORDCOMPLETION
add_to_sclist(MMAIN, "^]", 0, complete_a_word, 0);
diff --git a/src/nano.c b/src/nano.c
index 1aa8b276..d4597351 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2599,6 +2599,7 @@ int main(int argc, char **argv)
altright = get_keycode("kRIT3", ALT_RIGHT);
altup = get_keycode("kUP3", ALT_UP);
altdown = get_keycode("kDN3", ALT_DOWN);
+ altdelete = get_keycode("kDC3", ALT_DELETE);

shiftaltleft = get_keycode("kLFT4", SHIFT_ALT_LEFT);
shiftaltright = get_keycode("kRIT4", SHIFT_ALT_RIGHT);
diff --git a/src/nano.h b/src/nano.h
index 70cd353c..db726b6a 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -594,6 +594,7 @@ enum
#define ALT_RIGHT 0x422
#define ALT_UP 0x423
#define ALT_DOWN 0x424
+#define ALT_DELETE 0x427
#define SHIFT_ALT_LEFT 0x431
#define SHIFT_ALT_RIGHT 0x432
#define SHIFT_ALT_UP 0x433
diff --git a/src/proto.h b/src/proto.h
index a2834606..63494981 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -67,6 +67,7 @@ extern int shiftcontrolup, shiftcontroldown;
extern int shiftcontrolhome, shiftcontrolend;
extern int altleft, altright;
extern int altup, altdown;
+extern int altdelete;
extern int shiftaltleft, shiftaltright;
extern int shiftaltup, shiftaltdown;
#endif
diff --git a/src/winio.c b/src/winio.c
index 5a98456d..c8bfc98b 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -390,7 +390,9 @@ int parse_kbinput(WINDOW *win)
retval = keycode;
break;
case 1:
- if (keycode >= 0x80)
+ if (keycode == KEY_DC)
+ retval = ALT_DELETE;
+ else if (keycode >= 0x80)
retval = keycode;
else if (keycode == TAB_CODE)
retval = SHIFT_TAB;
@@ -576,7 +578,10 @@ int parse_kbinput(WINDOW *win)
return ALT_UP;
else if (retval == altdown)
return ALT_DOWN;
- else if (retval == shiftaltleft) {
+ else if (retval == altdelete) {
+ meta_key = TRUE;
+ return ALT_DELETE;
+ } else if (retval == shiftaltleft) {
shift_held = TRUE;
return KEY_HOME;
} else if (retval == shiftaltright) {
@@ -609,6 +614,11 @@ int parse_kbinput(WINDOW *win)
/* Are both Shift and Ctrl being held while Delete is pressed? */
if ((modifiers & 0x05) == 0x05 && retval == KEY_DC)
return CONTROL_SHIFT_DELETE;
+ /* Is Meta being held while Delete is pressed? */
+ if (modifiers == 0x08 && retval == KEY_DC) {
+ meta_key = TRUE;
+ return ALT_DELETE;
+ }
#endif
/* Is Ctrl being held? */
if (modifiers & 0x04) {
--
2.19.1
Benno Schulenberg
2018-10-28 13:41:04 UTC
Permalink
From: David Lawrence Ramsey <***@gmail.com>

This works on xterm, rxvt, Eterm, Konsole, and xfce4-terminal, which
generate "Esc [ 3 ; 3 ~", and urxvt, which generates "Esc Esc [ 3 ~".
---
src/winio.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

diff --git a/src/winio.c b/src/winio.c
index c8bfc98b..c59e3d9c 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -494,6 +494,16 @@ int parse_kbinput(WINDOW *win)
('a' <= *key_buffer && *key_buffer <= 'd'))) {
/* An iTerm2/Eterm/rxvt sequence: ^[ ^[ [ X. */
double_esc = TRUE;
+#ifndef NANO_TINY
+ } else if (keycode == '[' && key_buffer_len > 1 &&
+ key_buffer[0] == '3' && key_buffer[1] == '~') {
+ /* Esc Esc [ 3 ~ is Alt-Delete on urxvt. First consume
+ * the two waiting codes, then return the result. */
+ kbinput = get_input(win, 1);
+ kbinput = get_input(win, 1);
+ retval = ALT_DELETE;
+ escapes = 0;
+#endif
} else {
/* Two escapes followed by a non-escape, and there are more
* codes waiting: combined meta and escape sequence mode. */
@@ -1114,6 +1124,9 @@ int convert_sequence(const int *seq, size_t length, int *consumed)
#ifndef NANO_TINY
if (length > 4 && seq[2] == ';' && seq[4] == '~') {
*consumed = 5;
+ if (seq[3] == '3')
+ /* Esc [ 3 ; 3 ~ == Alt-Delete on xterm/rxvt/Eterm/Terminal. */
+ return ALT_DELETE;
if (seq[3] == '5')
/* Esc [ 3 ; 5 ~ == Ctrl-Delete on xterm. */
return CONTROL_DELETE;
--
2.19.1
Brand Huntsman
2018-11-08 22:36:34 UTC
Permalink
On Sun, 28 Oct 2018 14:41:01 +0100
Post by Benno Schulenberg
+void zap_text(void)
All other bindable functions have a "do_" prefix, why was it dropped from zap?
Benno Schulenberg
2018-11-11 12:45:39 UTC
Permalink
Post by Brand Huntsman
On Sun, 28 Oct 2018 14:41:01 +0100
Post by Benno Schulenberg
+void zap_text(void)
All other bindable functions have a "do_" prefix, why was it dropped from zap?
New style. Starting with complete_a_word(), bindables no longer always
start with "do_": record_macro(), run_macro(). And total_refresh().

Benno

Loading...