1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
<h3 class="section">Prefix Keys</h3> <p>A <em>prefix key</em> is a key sequence whose binding is a keymap. The keymap defines what to do with key sequences that extend the prefix key. For example, <kbd>C-x</kbd> is a prefix key, and it uses a keymap that is also stored in the variable <code>ctl-x-map</code>. This keymap defines bindings for key sequences starting with <kbd>C-x</kbd>. </p> <p>Some of the standard Emacs prefix keys use keymaps that are also found in Lisp variables: </p> <ul> <li> <code>esc-map</code> is the global keymap for the <tt class="key">ESC</tt> prefix key. Thus, the global definitions of all meta characters are actually found here. This map is also the function definition of <code>ESC-prefix</code>. </li>
<li> <code>help-map</code> is the global keymap for the <kbd>C-h</kbd> prefix key. </li>
<li> <code>mode-specific-map</code> is the global keymap for the prefix key <kbd>C-c</kbd>. This map is actually global, not mode-specific, but its name provides useful information about <kbd>C-c</kbd> in the output of <kbd>C-h b</kbd> (<code>display-bindings</code>), since the main use of this prefix key is for mode-specific bindings. </li>
<li> <code>ctl-x-map</code> is the global keymap used for the <kbd>C-x</kbd> prefix key. This map is found via the function cell of the symbol <code>Control-X-prefix</code>. </li>
<li> <code>mule-keymap</code> is the global keymap used for the <kbd>C-x <span class="key">RET</span></kbd> prefix key. </li>
<li> <code>ctl-x-4-map</code> is the global keymap used for the <kbd>C-x 4</kbd> prefix key. </li>
<li> <code>ctl-x-5-map</code> is the global keymap used for the <kbd>C-x 5</kbd> prefix key. </li>
<li> <code>2C-mode-map</code> is the global keymap used for the <kbd>C-x 6</kbd> prefix key. </li>
<li> <code>tab-prefix-map</code> is the global keymap used for the <kbd>C-x t</kbd> prefix key. </li>
<li> <code>vc-prefix-map</code> is the global keymap used for the <kbd>C-x v</kbd> prefix key. </li>
<li> <code>goto-map</code> is the global keymap used for the <kbd>M-g</kbd> prefix key. </li>
<li> <code>search-map</code> is the global keymap used for the <kbd>M-s</kbd> prefix key. </li>
<li> The other Emacs prefix keys are <kbd>C-x @</kbd>, <kbd>C-x a i</kbd>, <kbd>C-x <span class="key">ESC</span></kbd> and <kbd><span class="key">ESC</span> <span class="key">ESC</span></kbd>. They use keymaps that have no special names. </li>
</ul> <p>The keymap binding of a prefix key is used for looking up the event that follows 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 <kbd>C-x</kbd> is the symbol <code>Control-X-prefix</code>, whose function cell holds the keymap for <kbd>C-x</kbd> commands. (The same keymap is also the value of <code>ctl-x-map</code>.) </p> <p>Prefix key definitions can appear in any active keymap. The definitions of <kbd>C-c</kbd>, <kbd>C-x</kbd>, <kbd>C-h</kbd> and <tt class="key">ESC</tt> 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. See <a href="active-keymaps">Active Keymaps</a>. </p> <p>If a key is defined as a prefix in more than one active map, then its 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. </p> <p>In the following example, we make <kbd>C-p</kbd> a prefix key in the local keymap, in such a way that <kbd>C-p</kbd> is identical to <kbd>C-x</kbd>. Then the binding for <kbd>C-p C-f</kbd> is the function <code>find-file</code>, just like <kbd>C-x C-f</kbd>. The key sequence <kbd>C-p 6</kbd> is not found in any active keymap. </p> <div class="example"> <pre class="example">(use-local-map (make-sparse-keymap))
⇒ nil
</pre>
<pre class="example">(local-set-key "\C-p" ctl-x-map)
⇒ nil
</pre>
<pre class="example">(key-binding "\C-p\C-f")
⇒ find-file
</pre>
<pre class="example">(key-binding "\C-p6")
⇒ nil
</pre>
</div> <dl> <dt id="define-prefix-command">Function: <strong>define-prefix-command</strong> <em>symbol &optional mapvar prompt</em>
</dt> <dd>
<p>This function prepares <var>symbol</var> for use as a prefix key’s binding: it creates a sparse keymap and stores it as <var>symbol</var>’s function definition. Subsequently binding a key sequence to <var>symbol</var> will make that key sequence into a prefix key. The return value is <code>symbol</code>. </p> <p>This function also sets <var>symbol</var> as a variable, with the keymap as its value. But if <var>mapvar</var> is non-<code>nil</code>, it sets <var>mapvar</var> as a variable instead. </p> <p>If <var>prompt</var> is non-<code>nil</code>, that becomes the overall prompt string for the keymap. The prompt string should be given for menu keymaps (see <a href="defining-menus">Defining Menus</a>). </p>
</dd>
</dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Keys.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Prefix-Keys.html</a>
</p>
</div>
|