nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] input: erase the next word when Ctrl is held while


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] input: erase the next word when Ctrl is held while pressing Delete
Date: Fri, 20 Jul 2018 19:57:04 +0200

From: Marco Diego Aurélio Mesquita <address@hidden>

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 <address@hidden>
Signed-off-by: Benno Schulenberg <address@hidden>
---
 src/global.c |  2 ++
 src/nano.c   |  1 +
 src/nano.h   |  1 +
 src/proto.h  |  1 +
 src/winio.c  | 15 ++++++++++++++-
 5 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/global.c b/src/global.c
index dba83018..f53a6d85 100644
--- 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
index eb0007ed..fe156ec8 100644
--- 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
index e05ae523..6e4cceee 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_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
index d9efce9d..8df928f0 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 controldelete;
 #ifndef NANO_TINY
 extern int shiftcontrolleft;
 extern int shiftcontrolright;
diff --git a/src/winio.c b/src/winio.c
index a22c1891..4ae6d83b 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 == 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. */
-- 
2.17.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]