nano-devel
[Top][All Lists]
Advanced

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

[PATCH] bindings: allow to bind shifted Meta+letter combinations with Sh


From: Benno Schulenberg
Subject: [PATCH] bindings: allow to bind shifted Meta+letter combinations with Sh-M-X
Date: Tue, 21 Jan 2020 12:49:22 +0100

As long as the user does not define any Sh-M-X bindings in their nanorc,
<Shift> and <CapsLock> will not have any effect on <Alt+letter> combos.
But as soon as any Sh-M-X combination is bound, <Shift+Alt+letter> will
be seen as different from the unshifted keystroke.

This kind of addresses https://savannah.gnu.org/bugs/?54659.
Requested-by: Peter Passchier <address@hidden>
---
 src/global.c | 12 +++++++++++-
 src/nano.c   |  4 ++++
 src/proto.h  |  1 +
 src/winio.c  |  6 +++---
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/global.c b/src/global.c
index 20eee896..33dda198 100644
--- a/src/global.c
+++ b/src/global.c
@@ -33,6 +33,8 @@ volatile sig_atomic_t the_window_resized = FALSE;
 
 bool on_a_vt = FALSE;
                /* Whether we're running on a Linux console (a VT). */
+bool shifted_metas = FALSE;
+               /* Whether any Sh-M-<letter> combo has been bound. */
 
 bool meta_key;
                /* Whether the current keystroke is a Meta key. */
@@ -514,6 +516,14 @@ int keycode_from_string(const char *keystring)
                return KEY_IC;
        else if (strcasecmp(keystring, "Del") == 0)
                return KEY_DC;
+#ifdef ENABLE_NANORC
+       else if (strncasecmp(keystring, "Sh-M-", 5) == 0 &&
+                               'a' <= (keystring[5] | 0x20) && (keystring[5] | 
0x20) <= 'z' &&
+                               keystring[6] == '\0') {
+               shifted_metas = TRUE;
+               return (keystring[5] & 0xDF);
+       }
+#endif
        else
                return -1;
 }
@@ -522,7 +532,7 @@ int keycode_from_string(const char *keystring)
 void assign_keyinfo(keystruct *s, const char *keystring, const int keycode)
 {
        s->keystr = keystring;
-       s->meta = (keystring[0] == 'M' && keycode < 0x7F);
+       s->meta = ((keystring[0] == 'M' || keystring[0] == 'S') && keycode < 
0x7F);
        s->keycode = (keycode ? keycode : keycode_from_string(keystring));
 }
 
diff --git a/src/nano.c b/src/nano.c
index 9c25c5ca..833c7952 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1373,6 +1373,10 @@ void unbound_key(int code)
        else if (meta_key) {
                if (code == '[')
                        statusline(ALERT, _("Unbindable key: M-["));
+#ifdef ENABLE_NANORC
+               else if (shifted_metas && 'A' <= code && code <= 'Z')
+                       statusline(ALERT, _("Unbound key: Sh-M-%c"), code);
+#endif
                else
                        statusline(ALERT, _("Unbound key: M-%c"), 
toupper(code));
        } else if (code == ESC_CODE)
diff --git a/src/proto.h b/src/proto.h
index 89c48d57..3ed7f28e 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -27,6 +27,7 @@ extern volatile sig_atomic_t the_window_resized;
 #endif
 
 extern bool on_a_vt;
+extern bool shifted_metas;
 
 extern bool meta_key;
 extern bool shift_held;
diff --git a/src/winio.c b/src/winio.c
index 8beda17f..cf8dcd38 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -391,7 +391,7 @@ int parse_kbinput(WINDOW *win)
                                 * meta key sequence mode. */
                                if (!solitary || (keycode >= 0x20 && keycode < 
0x7F))
                                        meta_key = TRUE;
-                               retval = tolower(keycode);
+                               retval = (shifted_metas) ? keycode : 
tolower(keycode);
                        } else
                                /* One escape followed by a non-escape, and 
there
                                 * are more codes waiting: escape sequence 
mode. */
@@ -466,7 +466,7 @@ int parse_kbinput(WINDOW *win)
                                                 * or control character 
sequence mode. */
                                                if (!solitary) {
                                                        meta_key = TRUE;
-                                                       retval = 
tolower(keycode);
+                                                       retval = 
(shifted_metas) ? keycode : tolower(keycode);
                                                } else
                                                        retval = 
get_control_kbinput(keycode);
                                        else {
@@ -495,7 +495,7 @@ int parse_kbinput(WINDOW *win)
                        if (key_buffer_len == 0) {
                                if (!solitary) {
                                        meta_key = TRUE;
-                                       retval = tolower(keycode);
+                                       retval = (shifted_metas) ? keycode : 
tolower(keycode);
                                } else
                                        /* Three escapes followed by a 
non-escape, and no
                                         * other codes are waiting: normal 
input mode. */
-- 
2.24.1




reply via email to

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