开发者

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

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.

I tried local-unset-key but it only unbinds keys from the curre开发者_如何转开发nt major mode's map.

How do I remove C-c/ 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 C-c /... 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")
..
..
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜