Here are the functions and variables pertaining to key lookup.
lookup-key
. Here are examples:
(lookup-key (current-global-map) "\C-x\C-f") => find-file (lookup-key (current-global-map) "\C-x\C-f12345") => 2
If the string or vector key is not a valid key sequence according to the prefix keys specified in keymap, it must be "too long" and have extra events at the end that do not fit into a single key sequence. Then the value is a number, the number of events at the front of key that compose a complete key.
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 section Format of Keymaps.)
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 section 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 found is not a prefix definition (a keymap or a symbol defined as a keymap), 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).
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. Here is an illustration:
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!
Go to the first, previous, next, last section, table of contents.