Next: Key Lookup Prev: Prefix Keys Up: Keymaps
Emacs normally contains many keymaps; at any given time, just a few
of them are "active" in that they participate in the interpretation of
user input. These are the global keymap, the current buffer's local
keymap, and the keymaps of any enabled minor modes.
The "global keymap" holds the bindings of keys that are defined
regardless of the current buffer, such as `C-f'. The variable
`global-map' holds this keymap, which is always active.
Each buffer may have another keymap, its "local keymap", which may
contain new or overriding definitions for keys. At all times, the
current buffer's local keymap is active. Text properties can specify an
alternative local map for certain parts of the buffer; see *Note
Each minor mode may have a keymap; if it does, the keymap is active
whenever the minor mode is enabled.
All the active keymaps are used together to determine what command to
execute when a key is entered. The key lookup proceeds as described
earlier (Note: Key Lookup.), but Emacs *first* searches for the key
in the minor mode maps (one map at a time); if they do not supply a
binding for the key, Emacs searches the local map; if that too has no
binding, Emacs then searches the global map.
Since every buffer that uses the same major mode normally uses the
very same local keymap, it may appear as if the keymap is local to the
mode. A change to the local keymap of a buffer (using `local-set-key',
for example) will be seen also in the other buffers that share that
The local keymaps that are used for Lisp mode, C mode, and several
other major modes exist even if they have not yet been used. These
local maps are the values of the variables `lisp-mode-map',
`c-mode-map', and so on. For most other modes, which are less
frequently used, the local keymap is constructed only when the mode is
used for the first time in a session.
The minibuffer has local keymaps, too; they contain various
completion and exit commands. Note: Minibuffers.
Note: Standard Keymaps, for a list of standard keymaps.
- Variable: global-map
This variable contains the default global keymap that maps Emacs
keyboard input to commands. Normally this keymap is the global
keymap. The default global keymap is a full keymap that binds
`self-insert-command' to all of the printing characters.
- Function: current-global-map
This function returns the current global keymap. This is always
the same as the value of `global-map' unless you change one or the
=> (keymap [set-mark-command beginning-of-line ...
- Function: current-local-map
This function returns the current buffer's local keymap, or `nil'
if it has none. In the following example, the keymap for the
`*scratch*' buffer (using Lisp Interaction mode) is a sparse keymap
in which the entry for ESC, ASCII code 27, is another sparse
(10 . eval-print-last-sexp)
(9 . lisp-indent-line)
(127 . backward-delete-char-untabify)
(24 . eval-defun)
(17 . indent-sexp)))
- Function: current-minor-mode-maps
This function returns a list of the keymaps of currently enabled
- Function: use-global-map KEYMAP
This function makes KEYMAP the new current global keymap. It
It is very unusual to change the global keymap.
- Function: use-local-map KEYMAP
This function makes KEYMAP the new current local keymap of the
current buffer. If KEYMAP is `nil', then there will be no local
keymap. It returns `nil'. Most major modes use this function.
- Variable: minor-mode-map-alist
This variable is an alist describing keymaps that may or may not be
active according to the values of certain variables. Its elements
look like this:
(VARIABLE . KEYMAP)
The keymap KEYMAP is active whenever VARIABLE has a non-`nil'
value. Typically VARIABLE is the variable which enables or
disables a minor mode. Note: Keymaps and Minor Modes.
When more than one minor mode keymap is active, their order of
priority is the order of `minor-mode-map-alist'.
See also `minor-mode-key-binding' in Note: Functions for Key
automatically generated by info2www