When I evaluate (local-key-binding key)
for any arbitrary key that does not have a local binding, I expect a return value of nil
, but I almost always get a 1
. If the key actually does have a local binding (say from a major mode) in the current buffer, then local-key-binding
behaves as expected and returns the function to which the key is bound.
My question then, is why does local-key-binding
often return 1
when there is in fact no local binding for the given key?
As an example, after opening emacs with emacs -Q
, type
(key-binding (kbd "C-h h"))
(local-key-binding (kbd "C-h h"))
in the scratch buffer and evaluate each of the forms. Notice that key-binding
returns view-hello-file
, and local-key-binding
return 1
. The binding for C-h h
is defined globally, not locally, so I expect local-key-binding
to return nil
. Now try
(local-set-key (kbd "C-h h") 'describe-bindings)
(key-binding (kbd "C-h h"))
(local-key-binding (kbd "C-h h"))
and evaluate each of the forms. Notice that both key-binding
and local-key-binding
return describe-bindings
. Now try
(local-unset-key (kbd "C-h h"))
(key-binding (kbd "C-h h"))
(local-key-binding (kbd "C-h h"))
and evaluate each of the forms. Notice that key-binding
has gone back to view-hello-file
, and local-key-binding
now shows nil
.