Permalink
Browse files

Add new command unbindkey for removing keybindings

  • Loading branch information...
1 parent 5643f99 commit 8a921b5e61689654774fef672165f4c56c01036d @leonidg leonidg committed Mar 21, 2010
Showing with 64 additions and 2 deletions.
  1. +38 −1 commands.c
  2. +1 −1 keybinding.c
  3. +25 −0 keymap.c
View
@@ -90,7 +90,16 @@ const owl_cmd commands_to_init[]
"Binds a key sequence to a command within a keymap.\n"
"Use 'show keymaps' to see the existing keymaps.\n"
"Key sequences may be things like M-C-t or NPAGE.\n\n"
- "Ex.: bindkey recv C-b command zwrite -c barnowl"),
+ "Ex.: bindkey recv C-b command zwrite -c barnowl"
+ "SEE ALSO: bindkey"),
+
+ OWLCMD_ARGS("unbindkey", owl_command_unbindkey, OWL_CTX_ANY,
+ "removes a binding in a keymap",
+ "bindkey <keymap> <keyseq>",
+ "Removes a binding of a key sequence within a keymap.\n"
+ "Use 'show keymaps' to see the existing keymaps.\n"
+ "Ex.: unbindkey recv H"
+ "SEE ALSO: bindkey"),
OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
"send a zephyr",
@@ -1672,6 +1681,34 @@ char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
return NULL;
}
+
+char *owl_command_unbindkey(int argc, const char *const *argv)
+{
+ owl_keymap *km;
+ int ret;
+
+ if (argc < 3) {
+ owl_function_makemsg("Usage: bindkey <keymap> <binding>");
+ return NULL;
+ }
+ km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
+ if (!km) {
+ owl_function_makemsg("No such keymap '%s'", argv[1]);
+ return NULL;
+ }
+ ret = owl_keymap_remove_binding(km, argv[2]);
+ if (ret == -1) {
+ owl_function_makemsg("Unable to unbind '%s' in keymap '%s'.",
+ argv[2], argv[1]);
+ return NULL;
+ } else if (ret == -2) {
+ owl_function_makemsg("No such binding '%s' in keymap '%s'.",
+ argv[2], argv[1]);
+ }
+ return NULL;
+}
+
+
void owl_command_quit(void)
{
owl_function_quit();
View
@@ -45,7 +45,7 @@ int owl_keybinding_make_keys(owl_keybinding *kb, const char *keyseq)
return(-1);
}
kb->keys = owl_malloc(nktokens*sizeof(int));
- for (i = 0; i < nktokens; i++) {
+ for (i=0; i<nktokens; i++) {
kb->keys[i] = owl_keypress_fromstring(ktokens[i]);
if (kb->keys[i] == ERR) {
atokenize_delete(ktokens, nktokens);
View
@@ -50,8 +50,33 @@ int owl_keymap_create_binding(owl_keymap *km, const char *keyseq, const char *co
}
}
return owl_list_append_element(&km->bindings, kb);
+
}
+/* removes the binding associated with the keymap */
+int owl_keymap_remove_binding(owl_keymap *km, const char *keyseq)
+{
+ owl_keybinding *kb, *curkb;
+ int i;
+
+ if ((kb = owl_malloc(sizeof(owl_keybinding))) == NULL) return(-1);
+ if (0 != owl_keybinding_make_keys(kb, keyseq)) {
+ owl_free(kb);
+ return(-1);
+ }
+
+ for (i = owl_list_get_size(&km->bindings)-1; i >= 0; i--) {
+ curkb = owl_list_get_element(&km->bindings, i);
+ if (owl_keybinding_equal(curkb, kb)) {
+ owl_list_remove_element(&km->bindings, i);
+ owl_keybinding_delete(curkb);
+ return(0);
+ }
+ }
+ return(-2);
+}
+
+
/* returns a summary line describing this keymap. the caller must free. */
char *owl_keymap_summary(const owl_keymap *km)
{

0 comments on commit 8a921b5

Please sign in to comment.