(lispref.info)Prefix Keys

Next: Active Keymaps Prev: Inheritance and Keymaps Up: Keymaps

Prefix Keys

   A "prefix key" has an associated keymap which defines what to do
with key sequences that start with the prefix key.  For example, `C-x'
is a prefix key, and it uses a keymap which is also stored in the
variable `ctl-x-map'.  Here is a list of the standard prefix keys of
Emacs and their keymaps:

   * `help-map' is used for events that follow `C-h'.

   * `mode-specific-map' is for events that follow `C-c'.  This map is
     not actually mode specific; its name was chosen to be informative
     for the user in `C-h b' (`display-bindings'), where it describes
     the main use of the `C-c' prefix key.

   * `ctl-x-map' is the variable name for the map used for events that
     follow `C-x'.  This map is also the function definition of

   * `ctl-x-4-map' is used for events that follow `C-x 4'.

   * `ctl-x-5-map' used is for events that follow `C-x 5'.

   * A nameless keymap is used for events that follow `C-x n'.  Others
     are used for events following `C-x r' and `C-x a'.

   * `esc-map' is used for events that follow ESC.  Thus, the global
     definitions of all meta characters are actually found here.  This
     map is also the function definition of `ESC-prefix'.

   The binding of a prefix key is the keymap to use for looking up the
events that follow the prefix key.  (It may instead be a symbol whose
function definition is a keymap.  The effect is the same, but the symbol
serves as a name for the prefix key.)  Thus, the binding of `C-x' is
the symbol `Control-X-prefix', whose function definition is the keymap
for `C-x' commands.  (The same keymap is also the value of `ctl-x-map'.)

   Prefix key definitions of this sort can appear in any active keymap.
The definitions of `C-c', `C-x', `C-h' and ESC as prefix keys appear in
the global map, so these prefix keys are always available.  Major and
minor modes can redefine a key as a prefix by putting a prefix key
definition for it in the local map or the minor mode's map.  *Note
Active Keymaps::.

   If a key is defined as a prefix in more than one active map, then the
various definitions are in effect merged: the commands defined in the
minor mode keymaps come first, followed by those in the local map's
prefix definition, and then by those from the global map.

   In the following example, we make `C-p' a prefix key in the local
keymap, in such a way that `C-p' is identical to `C-x'.  Then the
binding for `C-p C-f' is the function `find-file', just like `C-x C-f'.
The key sequence `C-p 6' is not found in any active keymap.

     (use-local-map (make-sparse-keymap))
         => nil
     (local-set-key "\C-p" ctl-x-map)
         => nil
     (key-binding "\C-p\C-f")
         => find-file
     (key-binding "\C-p6")
         => nil

 - Function: define-prefix-command SYMBOL
     This function defines SYMBOL as a prefix command: it creates a
     full keymap and stores it as SYMBOL's function definition.
     Storing the symbol as the binding of a key makes the key a prefix
     key which has a name.  It also sets SYMBOL as a variable, to have
     the keymap as its value.  The function returns SYMBOL.

     In Emacs version 18, only the function definition of SYMBOL was
     set, not the value as a variable.

automatically generated by info2www