From cbda184461162e17297f335491acf956d756d0ea Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 18 Apr 2015 17:34:35 +0200 Subject: degesch: fix binding Meta keys At last. --- degesch.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/degesch.c b/degesch.c index 3fe9b38..7536b7f 100644 --- a/degesch.c +++ b/degesch.c @@ -1422,7 +1422,7 @@ on_readline_goto_buffer (int count, int key) { (void) count; - int n = (key & 0x7F) - '0'; + int n = UNMETA (key) - '0'; if (n < 0 || n > 9) return 0; @@ -1485,10 +1485,19 @@ on_readline_return (int count, int key) return 0; } +static void +app_readline_bind_meta (char key, rl_command_func_t cb) +{ + // One of these is going to work + char keyseq[] = { '\\', 'e', key, 0 }; + rl_bind_key (META (key), cb); + rl_bind_keyseq (keyseq, cb); +} + static int init_readline (void) { - // TODO: maybe use rl_make_bare_keymap() and start from there; + // XXX: maybe use rl_make_bare_keymap() and start from there; // our dear user could potentionally rig things up in a way that might // result in some funny unspecified behaviour @@ -1496,18 +1505,15 @@ init_readline (void) rl_add_defun ("next-buffer", on_readline_next_buffer, -1); // Redefine M-0 through M-9 to switch buffers - char keyseq[] = "\\M-0"; for (int i = 0; i <= 9; i++) - { - keyseq[3] = '0' + i; - rl_bind_keyseq (keyseq, on_readline_goto_buffer); - } + app_readline_bind_meta ('0' + i, on_readline_goto_buffer); rl_bind_keyseq ("\\C-p", rl_named_function ("previous-buffer")); rl_bind_keyseq ("\\C-n", rl_named_function ("next-buffer")); - rl_bind_keyseq ("\\M-p", rl_named_function ("previous-history")); - rl_bind_keyseq ("\\M-n", rl_named_function ("next-history")); + app_readline_bind_meta ('p', rl_named_function ("previous-history")); + app_readline_bind_meta ('n', rl_named_function ("next-history")); + // We need to hide the prompt first rl_bind_key (RETURN, on_readline_return); return 0; -- cgit v1.2.3-70-g09d2