From fe015eaa2634d8af5355655b04b70d87166868cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Diego=20Aur=C3=A9lio=20Mesquita?= Date: Thu, 12 Jul 2018 18:47:46 -0300 Subject: [PATCH] input: erase next word if ctrl is held when pressing delete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bind (until now unbound) 'cutwordright' to ^Del. The simmetrical case is not bound because ^Bsp often generates ^H and, in some terminals, it is the same as a plain Backspace. Signed-off-by: Marco Diego Aurélio Mesquita --- src/global.c | 3 ++- src/nano.c | 1 + src/nano.h | 1 + src/proto.h | 1 + src/winio.c | 13 ++++++++++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/global.c b/src/global.c index 089d530..e24c7f7 100644 --- a/src/global.c +++ b/src/global.c @@ -68,7 +68,7 @@ bool also_the_last = FALSE; int didfind = 0; /* Whether the last search found something. */ -int controlleft, controlright, controlup, controldown, controlhome, controlend; +int controlleft, controlright, controlup, controldown, controlhome, controlend, controldel; #ifndef NANO_TINY int shiftcontrolleft, shiftcontrolright, shiftcontrolup, shiftcontroldown; int shiftcontrolhome, shiftcontrolend; @@ -1160,6 +1160,7 @@ void shortcut_init(void) add_to_sclist(MMAIN, "M-;", 0, run_macro, 0); add_to_sclist(MMAIN, "M-U", 0, do_undo, 0); add_to_sclist(MMAIN, "M-E", 0, do_redo, 0); + add_to_sclist(MMAIN, "^Del", CONTROL_DEL, do_cut_next_word, 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 51bb2fe..af22601 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2582,6 +2582,7 @@ int main(int argc, char **argv) /* Ask for the codes for Control+Home/End. */ controlhome = get_keycode("kHOM5", CONTROL_HOME); controlend = get_keycode("kEND5", CONTROL_END); + controldel = get_keycode("kDC5", CONTROL_DEL); #ifndef NANO_TINY /* Ask for the codes for Shift+Control+Left/Right/Up/Down. */ shiftcontrolleft = get_keycode("kLFT6", SHIFT_CONTROL_LEFT); diff --git a/src/nano.h b/src/nano.h index e05ae52..1547d8e 100644 --- a/src/nano.h +++ b/src/nano.h @@ -585,6 +585,7 @@ enum #define CONTROL_DOWN 0x404 #define CONTROL_HOME 0x405 #define CONTROL_END 0x406 +#define CONTROL_DEL 0x407 #define SHIFT_CONTROL_LEFT 0x411 #define SHIFT_CONTROL_RIGHT 0x412 #define SHIFT_CONTROL_UP 0x413 diff --git a/src/proto.h b/src/proto.h index b2edf4d..10cc358 100644 --- a/src/proto.h +++ b/src/proto.h @@ -61,6 +61,7 @@ extern int controlup; extern int controldown; extern int controlhome; extern int controlend; +extern int controldel; #ifndef NANO_TINY extern int shiftcontrolleft; extern int shiftcontrolright; diff --git a/src/winio.c b/src/winio.c index a22c189..13fe16c 100644 --- a/src/winio.c +++ b/src/winio.c @@ -538,6 +538,8 @@ int parse_kbinput(WINDOW *win) return CONTROL_HOME; else if (retval == controlend) return CONTROL_END; + else if (retval == controldel) + return CONTROL_DEL; #ifndef NANO_TINY else if (retval == shiftcontrolleft) { shift_held = TRUE; @@ -1088,9 +1090,18 @@ int convert_sequence(const int *seq, size_t length, int *consumed) * Linux console/xterm/Terminal. */ if (length > 2 && seq[2] == '~') return KEY_DC; - if (length > 4 && seq[2] == ';' && seq[4] == '~') + if (length > 4 && seq[2] == ';' && seq[4] == '~') { /* Esc [ 3 ; x ~ == modified Delete on xterm. */ *consumed = 5; + /* Esc [ 3 ; 5 ~ == control Delete on xterm with -K. */ + if (seq[3] == '5') + return CONTROL_DEL; + } + /* Esc [ 3 ^ == control Delete on urxvt with -K. */ + if (length > 2 && seq[2] == '^') { + *consumed = 3; + return CONTROL_DEL; + } break; case '4': /* Esc [ 4 ~ == End on VT220/VT320/ * Linux console/xterm. */ -- 2.7.4