summaryrefslogtreecommitdiffstats
path: root/cmd-bind-key.c
diff options
context:
space:
mode:
authornicm <nicm>2016-09-12 15:40:58 +0000
committernicm <nicm>2016-09-12 15:40:58 +0000
commit2e5584c2b41df1c1b836c3229ea78f8ea3d81054 (patch)
tree1f790c7d13f657d2e22bb292c56968cbc84bf675 /cmd-bind-key.c
parentfed1e384ad7eb88cc6203e49d4efa8e5ed4edb59 (diff)
Allow repeat count to be specified in mode key tables with bind-key -R,
and set the default repeat count to 5 for WheelUp and WheelDown in copy-mode.
Diffstat (limited to 'cmd-bind-key.c')
-rw-r--r--cmd-bind-key.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/cmd-bind-key.c b/cmd-bind-key.c
index a829a2c5..88767245 100644
--- a/cmd-bind-key.c
+++ b/cmd-bind-key.c
@@ -36,9 +36,9 @@ const struct cmd_entry cmd_bind_key_entry = {
.name = "bind-key",
.alias = "bind",
- .args = { "cnrt:T:", 1, -1 },
- .usage = "[-cnr] [-t mode-table] [-T key-table] key command "
- "[arguments]",
+ .args = { "cnrR:t:T:", 1, -1 },
+ .usage = "[-cnr] [-t mode-table] [-R repeat-count] [-T key-table] key "
+ "command [arguments]",
.flags = 0,
.exec = cmd_bind_key_exec
@@ -97,11 +97,12 @@ enum cmd_retval
cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key)
{
struct args *args = self->args;
- const char *tablename;
+ const char *tablename, *arg;
const struct mode_key_table *mtab;
struct mode_key_binding *mbind, mtmp;
enum mode_key_cmd cmd;
- const char *arg;
+ char *cause;
+ u_int repeat;
tablename = args_get(args, 't');
if ((mtab = mode_key_findtable(tablename)) == NULL) {
@@ -145,6 +146,16 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key)
break;
}
+ repeat = 1;
+ if (args_has(args, 'R')) {
+ repeat = args_strtonum(args, 'R', 1, SHRT_MAX, &cause);
+ if (cause != NULL) {
+ cmdq_error(cmdq, "repeat count %s", cause);
+ free(cause);
+ return (CMD_RETURN_ERROR);
+ }
+ }
+
mtmp.key = key;
mtmp.mode = !!args_has(args, 'c');
if ((mbind = RB_FIND(mode_key_tree, mtab->tree, &mtmp)) == NULL) {
@@ -153,6 +164,7 @@ cmd_bind_key_mode_table(struct cmd *self, struct cmd_q *cmdq, key_code key)
mbind->mode = mtmp.mode;
RB_INSERT(mode_key_tree, mtab->tree, mbind);
}
+ mbind->repeat = repeat;
mbind->cmd = cmd;
mbind->arg = arg != NULL ? xstrdup(arg) : NULL;
return (CMD_RETURN_NORMAL);