nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit a67f6c60317dc72b632ba2e8990248205510e6d6
parent 8d8f5788ce5476539cb4b9870e24f1c26c34080d
Author: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
Date:   Thu, 12 Jul 2018 18:47:46 -0300

input: erase the next word when Ctrl is held while pressing Delete

Bind the until-now unbound function 'cutwordright' to <Ctrl+Delete>.
The complementary function, 'cutwordleft', is not bound by default
because on many terminals the keystroke <Ctrl+Backspace> generates
^H -- the canonical ASCII backspace character.  We cannot change the
existing action of ^H without upsetting some users.

Signed-off-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>

Diffstat:
Msrc/global.c | 2++
Msrc/nano.c | 1+
Msrc/nano.h | 1+
Msrc/proto.h | 1+
Msrc/winio.c | 15++++++++++++++-
5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/global.c b/src/global.c @@ -69,6 +69,7 @@ int didfind = 0; /* Whether the last search found something. */ int controlleft, controlright, controlup, controldown, controlhome, controlend; +int controldelete; #ifndef NANO_TINY int shiftcontrolleft, shiftcontrolright, shiftcontrolup, shiftcontroldown; int shiftcontrolhome, shiftcontrolend; @@ -1162,6 +1163,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_DELETE, 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 @@ -2578,6 +2578,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); + controldelete = get_keycode("kDC5", CONTROL_DELETE); #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 @@ -585,6 +585,7 @@ enum #define CONTROL_DOWN 0x404 #define CONTROL_HOME 0x405 #define CONTROL_END 0x406 +#define CONTROL_DELETE 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 @@ -61,6 +61,7 @@ extern int controlup; extern int controldown; extern int controlhome; extern int controlend; +extern int controldelete; #ifndef NANO_TINY extern int shiftcontrolleft; extern int shiftcontrolright; diff --git 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 == controldelete) + return CONTROL_DELETE; #ifndef NANO_TINY else if (retval == shiftcontrolleft) { shift_held = TRUE; @@ -609,6 +611,8 @@ int parse_kbinput(WINDOW *win) return CONTROL_HOME; else if (retval == KEY_END) return CONTROL_END; + else if (retval == KEY_DC) + return CONTROL_DELETE; } #ifndef NANO_TINY /* Are both Shift and Alt being held? */ @@ -1088,9 +1092,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; + if (seq[3] == '5') + /* Esc [ 3 ; 5 ~ == Ctrl-Delete on xterm. */ + return CONTROL_DELETE; + } + if (length > 2 && seq[2] == '^') { + /* Esc [ 3 ^ == Ctrl-Delete on urxvt. */ + *consumed = 3; + return CONTROL_DELETE; + } break; case '4': /* Esc [ 4 ~ == End on VT220/VT320/ * Linux console/xterm. */