summaryrefslogtreecommitdiffstats
path: root/cmd-bind-key.c
diff options
context:
space:
mode:
authornicm <nicm>2020-01-27 08:53:13 +0000
committernicm <nicm>2020-01-27 08:53:13 +0000
commitd0b8d036be97efc885f879aa63ce9bbb0efd8222 (patch)
tree44cfbf25fe998698cd423eb5a88a572426929715 /cmd-bind-key.c
parent2e39b621c9b29b58b4bfe761989b14f0f13d07b6 (diff)
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.
Diffstat (limited to 'cmd-bind-key.c')
-rw-r--r--cmd-bind-key.c12
1 files changed, 7 insertions, 5 deletions
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);
}