In emacs, how can I show shadowed/overridden key bindings for the current buffer?
They won't show up when running describe-bindings
(C-h b
).
In other words: how can I see if the modes active in a buffer have conflicting key bindings?
In emacs, how can I show shadowed/overridden key bindings for the current buffer?
They won't show up when running describe-bindings
(C-h b
).
In other words: how can I see if the modes active in a buffer have conflicting key bindings?
Just call describe-mode
: C-hm
The majority of mode docstrings will display their keymaps, and the method used to list them here also tells you if a binding is shadowed.
It doesn't tell you what it's shadowed by, but of course that's trivial to check with C-hc or C-hk.
e.g.:
key binding
--- -------
[...]
C-M-q indent-sexp
(that binding is currently shadowed by another mode)
That text is generated by the function substitute-command-keys
which processes the mode docstring when the documentation
function is called.
e.g.:
(substitute-command-keys "\\{lisp-interaction-mode-map}")
The following functions can also be useful:
(key-binding KEY &optional ACCEPT-DEFAULT NO-REMAP POSITION) ;; dominant binding
(global-key-binding KEYS &optional ACCEPT-DEFAULT)
(local-key-binding KEYS &optional ACCEPT-DEFAULT)
(minor-mode-key-binding KEY &optional ACCEPT-DEFAULT) ;; discover keymap(s)
for the heck of it I did this:
(define-key c++-mode-map "\C-c\C-s" 'kaw-sort-projects)
and then did C-h b (to see the bindings). And got this output :
Major Mode Bindings:
key binding
--- -------
C-c C-q c-indent-defun
C-c C-s kaw-sort-projects
C-c C-u c-up-conditional
C-c C-w subword-mode
so it does seem to be showing up.
Is this what you meant ?
created this function that gives you the previous value when you define a key
(defun define-key-warn (map key fxn)
"Bind a key and give info message if already bound"
(setq old-fxn (lookup-key map key))
(if old-fxn
(message "INFO: key %s was defined as %s" key old-fxn))
(define-key map key fxn)
)