>From fde4647e8a1c4f5b9ff9f09d005d49186dbffa94 Mon Sep 17 00:00:00 2001 From: Brand Huntsman Date: Fri, 19 Oct 2018 23:22:43 -0600 Subject: [PATCH 3/3] bind zap to M-Del key Signed-off-by: Brand Huntsman --- doc/nano.texi | 1 + src/global.c | 4 ++++ src/nano.c | 1 + src/nano.h | 1 + src/proto.h | 1 + src/winio.c | 14 ++++++++++++-- 6 files changed, 20 insertions(+), 2 deletions(-) diff --git a/doc/nano.texi b/doc/nano.texi index 431a5644..96624b14 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -1155,6 +1155,7 @@ current cursor position. @item zap Throw away the current line (or the marked region). +(This function is bound by default to .) @item cutwordleft Cuts from the cursor position to the beginning of the preceding word. diff --git a/src/global.c b/src/global.c index a0704c5e..84d9813b 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 @@ -487,6 +488,8 @@ int keycode_from_string(const char *keystring) else return -1; } else if (keystring[0] == 'M') { + if (strcasecmp(keystring, "M-Del") == 0) + return ALT_DELETE; if (strcasecmp(keystring, "M-Space") == 0) return (int)' '; if (keystring[1] == '-' && strlen(keystring) == 3) @@ -1158,6 +1161,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, do_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 1fdfcef3..49697446 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2600,6 +2600,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 1b3802ae..3e5fb0f0 100644 --- a/src/nano.h +++ b/src/nano.h @@ -597,6 +597,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 7574fc9a..190ef841 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 7f8a4e00..5267f954 100644 --- a/src/winio.c +++ b/src/winio.c @@ -395,7 +395,9 @@ int parse_kbinput(WINDOW *win) retval = keycode; break; case 1: - if (keycode >= 0x80) + if (keycode == KEY_DC) + retval = altdelete; + else if (keycode >= 0x80) retval = keycode; else if (keycode == TAB_CODE) retval = SHIFT_TAB; @@ -581,7 +583,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) { @@ -614,6 +619,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.18.1