简体   繁体   中英

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

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

I tried local-unset-key but it only unbinds keys from the current major mode's map.

How do I remove Cc/ from reftex-mode-map without making changes to reftex.el?

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)

You can use following command:

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

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

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")
..
..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM