GNU Emacs Lisp Reference Manual
Here are the functions and variables pertaining to key lookup.
If accept-defaults is non-nil, then lookup-key considers default bindings as well as bindings for the specific events in key. Otherwise, lookup-key reports only bindings for the specific sequence key, ignoring default bindings except when you explicitly ask about them. (To do this, supply t as an element of key; see Format of Keymaps.)
All the other functions described in this chapter that look up keys use lookup-key.
(lookup-key (current-global-map) "\C-x\C-f")
=> find-file
(lookup-key (current-global-map) "\C-x\C-f12345")
=> 2
If key contains a meta character, that character is implicitly replaced by a two-character sequence: the value of meta-prefix-char, followed by the corresponding non-meta character. Thus, the first example below is handled by conversion into the second example.
(lookup-key (current-global-map) "\M-f")
=> forward-word
(lookup-key (current-global-map) "\ef")
=> forward-word
Unlike read-key-sequence, this function does not modify the specified events in ways that discard information (see Key Sequence Input). In particular, it does not convert letters to lower case and it does not change drag events to clicks.
ding, but does not cause an error.nil if key is undefined in the keymaps. The argument accept-defaults controls checking for default bindings, as in lookup-key (above).
An error is signaled if key is not a string or a vector.
(key-binding "\C-x\C-f")
=> find-file
nil if it is undefined there. The argument accept-defaults controls checking for default bindings, as in lookup-key (above).
nil if it is undefined there. The argument accept-defaults controls checking for default bindings, as in lookup-key (above).
(modename . binding), where modename is the variable that enables the minor mode, and binding is key's binding in that mode. If key has no minor-mode bindings, the value is nil. If the first binding is not a prefix command, all subsequent bindings from other minor modes are omitted, since they would be completely shadowed. Similarly, the list omits non-prefix bindings that follow prefix bindings.
The argument accept-defaults controls checking for default bindings, as in lookup-key (above).
ESC. As long as the value of meta-prefix-char remains 27, key lookup translates M-b into ESC b, which is normally defined as the backward-word command. However, if you set meta-prefix-char to 24, the code for C-x, then Emacs will translate M-b into C-x b, whose standard binding is the switch-to-buffer command.
meta-prefix-char ; The default value.
=> 27
(key-binding "\M-b")
=> backward-word
?\C-x ; The print representation
=> 24 ; of a character.
(setq meta-prefix-char 24)
=> 24
(key-binding "\M-b")
=> switch-to-buffer ; Now, typing M-b is
; like typing C-x b.
(setq meta-prefix-char 27) ; Avoid confusion!
=> 27 ; Restore the default value!