summaryrefslogtreecommitdiff
path: root/devdocs/elisp/key-lookup.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/key-lookup.html')
-rw-r--r--devdocs/elisp/key-lookup.html14
1 files changed, 14 insertions, 0 deletions
diff --git a/devdocs/elisp/key-lookup.html b/devdocs/elisp/key-lookup.html
new file mode 100644
index 00000000..9ac87c84
--- /dev/null
+++ b/devdocs/elisp/key-lookup.html
@@ -0,0 +1,14 @@
+ <h3 class="section">Key Lookup</h3> <p><em>Key lookup</em> is the process of finding the binding of a key sequence from a given keymap. The execution or use of the binding is not part of key lookup. </p> <p>Key lookup uses just the event type of each event in the key sequence; the rest of the event is ignored. In fact, a key sequence used for key lookup may designate a mouse event with just its types (a symbol) instead of the entire event (a list). See <a href="input-events">Input Events</a>. Such a key sequence is insufficient for <code>command-execute</code> to run, but it is sufficient for looking up or rebinding a key. </p> <p>When the key sequence consists of multiple events, key lookup processes the events sequentially: the binding of the first event is found, and must be a keymap; then the second event’s binding is found in that keymap, and so on until all the events in the key sequence are used up. (The binding thus found for the last event may or may not be a keymap.) Thus, the process of key lookup is defined in terms of a simpler process for looking up a single event in a keymap. How that is done depends on the type of object associated with the event in that keymap. </p> <p>Let’s use the term <em>keymap entry</em> to describe the value found by looking up an event type in a keymap. (This doesn’t include the item string and other extra elements in a keymap element for a menu item, because <code>lookup-key</code> and other key lookup functions don’t include them in the returned value.) While any Lisp object may be stored in a keymap as a keymap entry, not all make sense for key lookup. Here is a table of the meaningful types of keymap entries: </p> <dl compact> <dt><code>nil</code></dt> <dd>
+ <p><code>nil</code> means that the events used so far in the lookup form an undefined key. When a keymap fails to mention an event type at all, and has no default binding, that is equivalent to a binding of <code>nil</code> for that event type. </p> </dd> <dt><var>command</var></dt> <dd>
+ <p>The events used so far in the lookup form a complete key, and <var>command</var> is its binding. See <a href="what-is-a-function">What Is a Function</a>. </p> </dd> <dt><var>array</var></dt> <dd>
+ <p>The array (either a string or a vector) is a keyboard macro. The events used so far in the lookup form a complete key, and the array is its binding. See <a href="keyboard-macros">Keyboard Macros</a>, for more information. </p> </dd> <dt><var>keymap</var></dt> <dd>
+ <p>The events used so far in the lookup form a prefix key. The next event of the key sequence is looked up in <var>keymap</var>. </p> </dd> <dt><var>list</var></dt> <dd>
+ <p>The meaning of a list depends on what it contains: </p> <ul> <li> If the <small>CAR</small> of <var>list</var> is the symbol <code>keymap</code>, then the list is a keymap, and is treated as a keymap (see above). </li>
+<li> If the <small>CAR</small> of <var>list</var> is <code>lambda</code>, then the list is a lambda expression. This is presumed to be a function, and is treated as such (see above). In order to execute properly as a key binding, this function must be a command—it must have an <code>interactive</code> specification. See <a href="defining-commands">Defining Commands</a>. </li>
+</ul> </dd> <dt><var>symbol</var></dt> <dd>
+ <p>The function definition of <var>symbol</var> is used in place of <var>symbol</var>. If that too is a symbol, then this process is repeated, any number of times. Ultimately this should lead to an object that is a keymap, a command, or a keyboard macro. </p> <p>Note that keymaps and keyboard macros (strings and vectors) are not valid functions, so a symbol with a keymap, string, or vector as its function definition is invalid as a function. It is, however, valid as a key binding. If the definition is a keyboard macro, then the symbol is also valid as an argument to <code>command-execute</code> (see <a href="interactive-call">Interactive Call</a>). </p> <p>The symbol <code>undefined</code> is worth special mention: it means to treat the key as undefined. Strictly speaking, the key is defined, and its binding is the command <code>undefined</code>; but that command does the same thing that is done automatically for an undefined key: it rings the bell (by calling <code>ding</code>) but does not signal an error. </p> <p><code>undefined</code> is used in local keymaps to override a global key binding and make the key undefined locally. A local binding of <code>nil</code> would fail to do this because it would not override the global binding. </p> </dd> <dt><var>anything else</var></dt> <dd><p>If any other type of object is found, the events used so far in the lookup form a complete key, and the object is its binding, but the binding is not executable as a command. </p></dd> </dl> <p>In short, a keymap entry may be a keymap, a command, a keyboard macro, a symbol that leads to one of them, or <code>nil</code>. </p><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 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/Key-Lookup.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Key-Lookup.html</a>
+ </p>
+</div>