Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I configure numerous additional keybindings, and sometimes I unintentially overwrite others. Is there a way to determine if a keybinding is taken before binding a key, and if so throw an error?

share|improve this question
up vote 10 down vote accepted

See function lookup-key. It will tell you whether a given key is defined in a given map, including in the global map, or even (with non-nil arg ACCEPT-DEFAULTS) whether it has a fallback (default) binding in the current context.

For example, if you want to see whether C-M-kp-+ is defined in the current mode's map:

(lookup-key (current-local-map) (kbd "<C-M-S-kp-add>"))

And if you want to see whether it has a global binding:

(lookup-key (current-global-map) (kbd "<C-M-S-kp-add>"))

And if you want to see if has a default behavior in the context of the current mode, even though it is not specifically defined:

(lookup-key (current-local-map) (kbd "<C-M-S-kp-add>") t)

See also: Key Lookup.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.