How to remove a key from a minor-mode keymap in Emacs?

前端 未结 3 1964
渐次进展
渐次进展 2020-12-29 18:37

I have globally assigned C-c/ to ace-jump-mode but reftex-mode (a minor mode for citations used with AucTeX) overrides this key with some function I never use.<

相关标签:
3条回答
  • 2020-12-29 19:24

    You can change an existing key map using define-key. By passing nil as the function to call, the key will become unbound. I guess that you should be able to do something like:

    (define-key reftex-mode-map "\C-c/" nil)
    

    Of course, you should do this in some kind of hook, for example:

    (defun my-reftex-hook ()
      (define-key reftex-mode-map "\C-c/" nil))
    (add-hook 'reftex-mode-hook 'my-reftex-hook)
    
    0 讨论(0)
  • 2020-12-29 19:25

    You can use following command:

    (define-key reftex-mode-map "\C-c/" nil)
    

    to unmap this function from C-c /... But reftex-mode should be loaded, so reftex-mode-map will available for modification

    0 讨论(0)
  • 2020-12-29 19:33

    This is how I do it. It could be improved, though.

     (defun get-key-combo (key)
      "Just return the key combo entered by the user"
      (interactive "kKey combo: ")
      key)
    
    (defun keymap-unset-key (key keymap)
        "Remove binding of KEY in a keymap
        KEY is a string or vector representing a sequence of keystrokes."
        (interactive
         (list (call-interactively #'get-key-combo)
               (completing-read "Which map: " minor-mode-map-alist nil t)))
        (let ((map (rest (assoc (intern keymap) minor-mode-map-alist))))
          (when map
            (define-key map key nil)
            (message  "%s unbound for %s" key keymap))))
    ;;
    ;; Then use it interativly
    ;; Or like this:
    
    (keymap-unset-key  '[C-M-left]   "paredit-mode")
    ..
    ..
    
    0 讨论(0)
提交回复
热议问题