nano-devel
[Top][All Lists]
Advanced

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

[Nano-devel] [PATCH 1/1] bindings: make ^Home and ^End go to top and tai


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH 1/1] bindings: make ^Home and ^End go to top and tail of buffer
Date: Thu, 6 Apr 2017 12:35:52 +0200

On some terminal emulators, Ctrl+Home and Ctrl+End produce special
keycodes, distinct from plain Home and End.  Make the users of those
emulators (and of the Linux console) glad by making ^Home and ^End
do the obvious thing, and the combinations with Shift too.
---
 src/global.c |  5 ++++-
 src/nano.c   |  6 ++++++
 src/nano.h   |  4 ++++
 src/proto.h  |  4 ++++
 src/winio.c  | 14 ++++++++++++++
 5 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/src/global.c b/src/global.c
index ea944ff0..1677dc23 100644
--- a/src/global.c
+++ b/src/global.c
@@ -59,9 +59,10 @@ message_type lastmessage = HUSH;
 filestruct *pletion_line = NULL;
        /* The line where the last completion was found, if any. */
 
-int controlleft, controlright, controlup, controldown;
+int controlleft, controlright, controlup, controldown, controlhome, controlend;
 #ifndef NANO_TINY
 int shiftcontrolleft, shiftcontrolright, shiftcontrolup, shiftcontroldown;
+int shiftcontrolhome, shiftcontrolend;
 int shiftaltleft, shiftaltright, shiftaltup, shiftaltdown;
 #endif
 
@@ -1078,8 +1079,10 @@ void shortcut_init(void)
     add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "F8", 0, do_page_down, 0);
     add_to_sclist(MMAIN|MHELP|MBROWSER|MLINTER, "PgDn", KEY_NPAGE, 
do_page_down, 0);
     add_to_sclist(MMAIN|MHELP, "M-\\", 0, do_first_line, 0);
+    add_to_sclist(MMAIN|MHELP, "^Home", CONTROL_HOME, do_first_line, 0);
     add_to_sclist(MMAIN|MHELP, "M-|", 0, do_first_line, 0);
     add_to_sclist(MMAIN|MHELP, "M-/", 0, do_last_line, 0);
+    add_to_sclist(MMAIN|MHELP, "^End", CONTROL_END, do_last_line, 0);
     add_to_sclist(MMAIN|MHELP, "M-?", 0, do_last_line, 0);
     add_to_sclist(MMAIN|MBROWSER, "M-W", 0, do_research, 0);
     add_to_sclist(MMAIN|MBROWSER, "F16", 0, do_research, 0);
diff --git a/src/nano.c b/src/nano.c
index 514ad51e..1bd9d353 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2514,12 +2514,18 @@ int main(int argc, char **argv)
     controlright = get_keycode("kRIT5", CONTROL_RIGHT);
     controlup = get_keycode("kUP5", CONTROL_UP);
     controldown = get_keycode("kDN5", CONTROL_DOWN);
+    /* Ask for the codes for Control+Home/End. */
+    controlhome = get_keycode("kHOM5", CONTROL_HOME);
+    controlend = get_keycode("kEND5", CONTROL_END);
 #ifndef NANO_TINY
     /* Ask for the codes for Shift+Control+Left/Right/Up/Down. */
     shiftcontrolleft = get_keycode("kLFT6", SHIFT_CONTROL_LEFT);
     shiftcontrolright = get_keycode("kRIT6", SHIFT_CONTROL_RIGHT);
     shiftcontrolup = get_keycode("kUP6", SHIFT_CONTROL_UP);
     shiftcontroldown = get_keycode("kDN6", SHIFT_CONTROL_DOWN);
+    /* Ask for the codes for Shift+Control+Home/End. */
+    shiftcontrolhome = get_keycode("kHOM6", SHIFT_CONTROL_HOME);
+    shiftcontrolend = get_keycode("kEND6", SHIFT_CONTROL_END);
     /* Ask for the codes for Shift+Alt+Left/Right/Up/Down. */
     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 f8c4da1e..9e245bd8 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -553,10 +553,14 @@ enum
 #define CONTROL_RIGHT 0x402
 #define CONTROL_UP 0x403
 #define CONTROL_DOWN 0x404
+#define CONTROL_HOME 0x411
+#define CONTROL_END 0x412
 #define SHIFT_CONTROL_LEFT 0x405
 #define SHIFT_CONTROL_RIGHT 0x406
 #define SHIFT_CONTROL_UP 0x407
 #define SHIFT_CONTROL_DOWN 0x408
+#define SHIFT_CONTROL_HOME 0x413
+#define SHIFT_CONTROL_END 0x414
 #define SHIFT_ALT_LEFT 0x409
 #define SHIFT_ALT_RIGHT 0x40a
 #define SHIFT_ALT_UP 0x40b
diff --git a/src/proto.h b/src/proto.h
index 66eefdcf..4c2cdc82 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -51,11 +51,15 @@ extern int controlleft;
 extern int controlright;
 extern int controlup;
 extern int controldown;
+extern int controlhome;
+extern int controlend;
 #ifndef NANO_TINY
 extern int shiftcontrolleft;
 extern int shiftcontrolright;
 extern int shiftcontrolup;
 extern int shiftcontroldown;
+extern int shiftcontrolhome;
+extern int shiftcontrolend;
 extern int shiftaltleft;
 extern int shiftaltright;
 extern int shiftaltup;
diff --git a/src/winio.c b/src/winio.c
index 757ce534..b4f533e3 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -505,6 +505,10 @@ int parse_kbinput(WINDOW *win)
        return CONTROL_UP;
     else if (retval == controldown)
        return CONTROL_DOWN;
+    else if (retval == controlhome)
+       return CONTROL_HOME;
+    else if (retval == controlend)
+       return CONTROL_END;
 #ifndef NANO_TINY
     else if (retval == shiftcontrolleft) {
        shift_held = TRUE;
@@ -518,6 +522,12 @@ int parse_kbinput(WINDOW *win)
     } else if (retval == shiftcontroldown) {
        shift_held = TRUE;
        return CONTROL_DOWN;
+    } else if (retval == shiftcontrolhome) {
+       shift_held = TRUE;
+       return CONTROL_HOME;
+    } else if (retval == shiftcontrolend) {
+       shift_held = TRUE;
+       return CONTROL_END;
     } else if (retval == shiftaltleft) {
        shift_held = TRUE;
        return KEY_HOME;
@@ -554,6 +564,10 @@ int parse_kbinput(WINDOW *win)
                return CONTROL_LEFT;
            else if (retval == KEY_RIGHT)
                return CONTROL_RIGHT;
+           else if (retval == KEY_HOME)
+               return CONTROL_HOME;
+           else if (retval == KEY_END)
+               return CONTROL_END;
        }
 #ifndef NANO_TINY
        /* Are both Shift and Alt being held? */
-- 
2.12.1




reply via email to

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