summaryrefslogtreecommitdiffstats
path: root/key-bindings.c
diff options
context:
space:
mode:
authornicm <nicm>2020-06-16 08:18:34 +0000
committernicm <nicm>2020-06-16 08:18:34 +0000
commit1bf9555e4f1ad19e1e6f97ede6fb19808ff1c267 (patch)
tree517c3ac9fd211c1294523af5f9e11104ae41edaa /key-bindings.c
parentafe4ea4250073e482c6ec6accfc539f873df6977 (diff)
d and D keys to reset to default in customize mode.
Diffstat (limited to 'key-bindings.c')
-rw-r--r--key-bindings.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/key-bindings.c b/key-bindings.c
index 9e198123..f11bb430 100644
--- a/key-bindings.c
+++ b/key-bindings.c
@@ -232,6 +232,38 @@ key_bindings_remove(const char *name, key_code key)
}
void
+key_bindings_reset(const char *name, key_code key)
+{
+ struct key_table *table;
+ struct key_binding *bd, *dd;
+
+ table = key_bindings_get_table(name, 0);
+ if (table == NULL)
+ return;
+
+ bd = key_bindings_get(table, key & ~KEYC_MASK_FLAGS);
+ if (bd == NULL)
+ return;
+
+ dd = key_bindings_get_default(table, bd->key);
+ if (dd == NULL) {
+ key_bindings_remove(name, bd->key);
+ return;
+ }
+
+ cmd_list_free(bd->cmdlist);
+ bd->cmdlist = dd->cmdlist;
+ bd->cmdlist->references++;
+
+ free((void *)bd->note);
+ if (dd->note != NULL)
+ bd->note = xstrdup(dd->note);
+ else
+ bd->note = NULL;
+ bd->flags = dd->flags;
+}
+
+void
key_bindings_remove_table(const char *name)
{
struct key_table *table;
@@ -248,6 +280,23 @@ key_bindings_remove_table(const char *name)
}
}
+void
+key_bindings_reset_table(const char *name)
+{
+ struct key_table *table;
+ struct key_binding *bd, *bd1;
+
+ table = key_bindings_get_table(name, 0);
+ if (table == NULL)
+ return;
+ if (RB_EMPTY(&table->default_key_bindings)) {
+ key_bindings_remove_table(name);
+ return;
+ }
+ RB_FOREACH_SAFE(bd, key_bindings, &table->key_bindings, bd1)
+ key_bindings_reset(name, bd->key);
+}
+
static enum cmd_retval
key_bindings_init_done(__unused struct cmdq_item *item, __unused void *data)
{