From d0b8d036be97efc885f879aa63ce9bbb0efd8222 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 27 Jan 2020 08:53:13 +0000 Subject: Add support for adding a note to a key binding (with bind-key -N) and use this to add descriptions to the default key bindings. A new -N flag to list-keys shows key bindings with notes rather than the default bind-key command used to create them. Change the default ? binding to use this to show a readable summary of keys. Also extend command-prompt to return the name of the key pressed and add a default binding (/) to show the note for the next key pressed Suggested by Alex Tremblay in GitHub issue 2000. --- cmd-bind-key.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'cmd-bind-key.c') diff --git a/cmd-bind-key.c b/cmd-bind-key.c index 2af15d29..27f75dd0 100644 --- a/cmd-bind-key.c +++ b/cmd-bind-key.c @@ -33,8 +33,8 @@ const struct cmd_entry cmd_bind_key_entry = { .name = "bind-key", .alias = "bind", - .args = { "cnrT:", 2, -1 }, - .usage = "[-cnr] [-T key-table] key " + .args = { "cnrN:T:", 2, -1 }, + .usage = "[-cnr] [-T key-table] [-N note] key " "command [arguments]", .flags = CMD_AFTERHOOK, @@ -46,10 +46,10 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; key_code key; - const char *tablename; + const char *tablename, *note; struct cmd_parse_result *pr; char **argv = args->argv; - int argc = args->argc; + int argc = args->argc, repeat; key = key_string_lookup_string(argv[0]); if (key == KEYC_NONE || key == KEYC_UNKNOWN) { @@ -63,6 +63,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item) tablename = "root"; else tablename = "prefix"; + repeat = args_has(args, 'r'); if (argc == 2) pr = cmd_parse_from_string(argv[1], NULL); @@ -79,6 +80,7 @@ cmd_bind_key_exec(struct cmd *self, struct cmdq_item *item) case CMD_PARSE_SUCCESS: break; } - key_bindings_add(tablename, key, args_has(args, 'r'), pr->cmdlist); + note = args_get(args, 'N'); + key_bindings_add(tablename, key, note, repeat, pr->cmdlist); return (CMD_RETURN_NORMAL); } -- cgit