summaryrefslogtreecommitdiff
path: root/degesch.c
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-04-18 17:34:35 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-04-18 17:34:35 +0200
commitcbda184461162e17297f335491acf956d756d0ea (patch)
treec2416f684eff207c2707c287c4ce2bd310667ea6 /degesch.c
parent5dbd6eaa7ec9a05162bad89d18604ac7e077a6ee (diff)
downloadxK-cbda184461162e17297f335491acf956d756d0ea.tar.gz
xK-cbda184461162e17297f335491acf956d756d0ea.tar.xz
xK-cbda184461162e17297f335491acf956d756d0ea.zip
degesch: fix binding Meta keys
At last.
Diffstat (limited to 'degesch.c')
-rw-r--r--degesch.c24
1 files 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;