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>
master
Benno Schulenberg 2020-01-21 12:31:34 +01:00
parent f7a3b996fa
commit 1cd5005d06
4 changed files with 18 additions and 4 deletions

View File

@ -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));
}

View File

@ -1359,6 +1359,10 @@ void unbound_key(int code)
#ifndef NANO_TINY
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));

View File

@ -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;

View File

@ -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. */