Next: Minibuffer Maps Prev: Prefix Keymaps Up: Key Bindings
So far we have explained the ins and outs of the global map. Major
modes customize Emacs by providing their own key bindings in "local
keymaps". For example, C mode overrides TAB to make it indent the
current line for C code. Portions of text in the buffer can specify
their own keymaps to substitute for the keymap of the buffer's major
Minor modes can also have local keymaps. Whenever a minor mode is
in effect, the definitions in its keymap override both the major mode's
local keymap and the global keymap.
The local keymaps for Lisp mode, C mode, and several other major
modes always exist even when not in use. These are kept in variables
named `lisp-mode-map', `c-mode-map', and so on. For major modes less
often used, the local keymap is normally constructed only when the mode
is used for the first time in a session. This is to save space.
All minor mode keymaps are created in advance. There is no way to
defer their creation until the minor mode is enabled.
A local keymap can locally redefine a key as a prefix key by defining
it as a prefix keymap. If the key is also defined globally as a prefix,
then its local and global definitions (both keymaps) effectively
combine: both of them are used to look up the event that follows the
prefix key. Thus, if the mode's local keymap defines `C-c' as another
keymap, and that keymap defines `C-z' as a command, this provides a
local meaning for `C-c C-z'. This does not affect other sequences that
start with `C-c'; If those sequences don't have their own local
bindings, their global bindings remain in effect.
Another way to think of this is that Emacs handles a multi-event key
sequence by looking in several keymaps, one by one, for a binding of the
whole key sequence. First it checks the minor mode keymaps for minor
modes that are enabled, then it checks the major mode's keymap, and then
it checks the global keymap. This is not precisely how key lookup
works, but it's good enough for understanding ordinary circumstances.
automatically generated by info2www