Changeset 8a921b5


Ignore:
Timestamp:
Mar 22, 2010, 11:13:41 PM (10 years ago)
Author:
Leonid Grinberg <leonidg@mit.edu>
Branches:
master, release-1.6, release-1.7, release-1.8, release-1.9
Children:
6b78afb
Parents:
5643f99
git-author:
Leonid Grinberg <leonidg@mit.edu> (03/21/10 01:12:40)
git-committer:
Leonid Grinberg <leonidg@mit.edu> (03/22/10 23:13:41)
Message:
Add new command unbindkey for removing keybindings
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rf449096 r8a921b5  
    9191              "Use 'show keymaps' to see the existing keymaps.\n"
    9292              "Key sequences may be things like M-C-t or NPAGE.\n\n"
    93               "Ex.: bindkey recv C-b command zwrite -c barnowl"),
     93              "Ex.: bindkey recv C-b command zwrite -c barnowl"
     94              "SEE ALSO: bindkey"),
     95
     96  OWLCMD_ARGS("unbindkey", owl_command_unbindkey, OWL_CTX_ANY,
     97              "removes a binding in a keymap",
     98              "bindkey <keymap> <keyseq>",
     99              "Removes a binding of a key sequence within a keymap.\n"
     100              "Use 'show keymaps' to see the existing keymaps.\n"
     101              "Ex.: unbindkey recv H"
     102              "SEE ALSO: bindkey"),
    94103
    95104  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
     
    16721681  return NULL;
    16731682}
     1683
     1684
     1685char *owl_command_unbindkey(int argc, const char *const *argv)
     1686{
     1687  owl_keymap *km;
     1688  int ret;
     1689
     1690  if (argc < 3) {
     1691    owl_function_makemsg("Usage: bindkey <keymap> <binding>");
     1692    return NULL;
     1693  }
     1694  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
     1695  if (!km) {
     1696    owl_function_makemsg("No such keymap '%s'", argv[1]);
     1697    return NULL;
     1698  }
     1699  ret = owl_keymap_remove_binding(km, argv[2]);
     1700  if (ret == -1) {
     1701    owl_function_makemsg("Unable to unbind '%s' in keymap '%s'.",
     1702                         argv[2], argv[1]);
     1703    return NULL;
     1704  } else if (ret == -2) {
     1705    owl_function_makemsg("No such binding '%s' in keymap '%s'.",
     1706                         argv[2], argv[1]);
     1707  }
     1708  return NULL;
     1709}
     1710
    16741711
    16751712void owl_command_quit(void)
  • keybinding.c

    r5643f99 r8a921b5  
    4646  }
    4747  kb->keys = owl_malloc(nktokens*sizeof(int));
    48   for (i = 0; i < nktokens; i++) {
     48  for (i=0; i<nktokens; i++) {
    4949    kb->keys[i] = owl_keypress_fromstring(ktokens[i]);
    5050    if (kb->keys[i] == ERR) {
  • keymap.c

    rbb0d439 r8a921b5  
    5151  }
    5252  return owl_list_append_element(&km->bindings, kb); 
    53 }
     53
     54}
     55
     56/* removes the binding associated with the keymap */
     57int owl_keymap_remove_binding(owl_keymap *km, const char *keyseq)
     58{
     59  owl_keybinding *kb, *curkb;
     60  int i;
     61
     62  if ((kb = owl_malloc(sizeof(owl_keybinding))) == NULL) return(-1);
     63  if (0 != owl_keybinding_make_keys(kb, keyseq)) {
     64    owl_free(kb);
     65    return(-1);
     66  }
     67
     68  for (i = owl_list_get_size(&km->bindings)-1; i >= 0; i--) {
     69    curkb = owl_list_get_element(&km->bindings, i);
     70    if (owl_keybinding_equal(curkb, kb)) {
     71      owl_list_remove_element(&km->bindings, i);
     72      owl_keybinding_delete(curkb);
     73      return(0);
     74    }
     75  }
     76  return(-2);
     77}
     78
    5479
    5580/* returns a summary line describing this keymap.  the caller must free. */
Note: See TracChangeset for help on using the changeset viewer.