Emacs contains many keymaps, but at any time only a few keymaps are active. When Emacs receives user input, it translates the input event (see Keymaps for Translating Sequences of Events), and looks for a key binding in the active keymaps.
Usually, the active keymaps are: (i) the keymap specified by the
keymap property, (ii) the keymaps of enabled minor modes, (iii)
the current buffer’s local keymap, and (iv) the global keymap, in that
order. Emacs searches for each input key sequence in all these
Of these usual keymaps, the highest-precedence one is specified
keymap text or overlay property at point, if any. (For
a mouse input event, Emacs uses the event position instead of point;
see Searching the Active Keymaps.)
Next in precedence are keymaps specified by enabled minor modes.
These keymaps, if any, are specified by the variables
minor-mode-map-alist. See Controlling the Active Keymaps.
Next in precedence is the buffer’s local keymap, containing
key bindings specific to the buffer. The minibuffer also has a local
keymap (see Introduction to Minibuffers). If there is a
text or overlay property at point, that specifies the local keymap to
use, in place of the buffer’s default local keymap.
The local keymap is normally set by the buffer’s major mode, and
every buffer with the same major mode shares the same local keymap.
Hence, if you call
keymap-local-set (see Commands for Binding Keys)
to change the local keymap in one buffer, that also affects the local
keymaps in other buffers with the same major mode.
Finally, the global keymap contains key bindings that are
defined regardless of the current buffer, such as C-f. It is
always active, and is bound to the variable
Apart from the above usual keymaps, Emacs provides special ways
for programs to make other keymaps active. Firstly, the variable
overriding-local-map specifies a keymap that replaces the usual
active keymaps, except for the global keymap. Secondly, the
a keymap that takes precedence over all other keymaps
overriding-local-map); this is normally used for
modal/transient key bindings (the function
provides a convenient interface for this). See Controlling the Active Keymaps, for details.
Making keymaps active is not the only way to use them. Keymaps are
also used in other ways, such as for translating events within
read-key-sequence. See Keymaps for Translating Sequences of Events.
See Standard Keymaps, for a list of some standard keymaps.
This returns the list of active keymaps that would be used by the
command loop in the current circumstances to look up a key sequence.
Normally it ignores
overriding-terminal-local-map, but if olp is non-
then it pays attention to them. position can optionally be either
an event position as returned by
event-start or a buffer
position, and may change the keymaps as described for
keymap-lookup (see keymap-lookup).