nano

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

commit 1cd5005d0675ad475a2daac6e77ef17357a93a41
parent f7a3b996fa7e7406bb661e5a54a0f52196b0ead9
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 21 Jan 2020 12:31:34 +0100

bindings: allow to bind shifted Meta+letter combinations with Sh-M-X

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 fulfills https://savannah.gnu.org/bugs/?54659.
Requested-by: Peter Passchier <peter@passchier.net>

Diffstat:
Msrc/global.c | 11++++++++++-
Msrc/nano.c | 4++++
Msrc/proto.h | 1+
Msrc/winio.c | 6+++---
4 files changed, 18 insertions(+), 4 deletions(-)

diff --git 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. */ @@ -505,6 +507,13 @@ int keycode_from_string(const char *keystring) return (int)' '; else return -1; +#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] & 0x5F); +#endif } else if (keystring[0] == 'F') { int fn = atoi(&keystring[1]); if (fn < 1 || fn > 24) @@ -522,7 +531,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 @@ -1360,6 +1360,10 @@ void unbound_key(int code) else if (code < 0x20) statusline(ALERT, _("Unbindable key: M-^%c"), code + 0x40); #endif +#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 @@ -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 @@ -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. */