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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<h3 class="section">Information from the Command Loop</h3> <p>The editor command loop sets several Lisp variables to keep status records for itself and for commands that are run. With the exception of <code>this-command</code> and <code>last-command</code> it’s generally a bad idea to change any of these variables in a Lisp program. </p> <dl> <dt id="last-command">Variable: <strong>last-command</strong>
</dt> <dd>
<p>This variable records the name of the previous command executed by the command loop (the one before the current command). Normally the value is a symbol with a function definition, but this is not guaranteed. </p> <p>The value is copied from <code>this-command</code> when a command returns to the command loop, except when the command has specified a prefix argument for the following command. </p> <p>This variable is always local to the current terminal and cannot be buffer-local. See <a href="multiple-terminals">Multiple Terminals</a>. </p>
</dd>
</dl> <dl> <dt id="real-last-command">Variable: <strong>real-last-command</strong>
</dt> <dd><p>This variable is set up by Emacs just like <code>last-command</code>, but never altered by Lisp programs. </p></dd>
</dl> <dl> <dt id="last-repeatable-command">Variable: <strong>last-repeatable-command</strong>
</dt> <dd><p>This variable stores the most recently executed command that was not part of an input event. This is the command <code>repeat</code> will try to repeat, See <a href="https://www.gnu.org/software/emacs/manual/html_node/emacs/Repeating.html#Repeating">Repeating</a> in <cite>The GNU Emacs Manual</cite>. </p></dd>
</dl> <dl> <dt id="this-command">Variable: <strong>this-command</strong>
</dt> <dd>
<p>This variable records the name of the command now being executed by the editor command loop. Like <code>last-command</code>, it is normally a symbol with a function definition. </p> <p>The command loop sets this variable just before running a command, and copies its value into <code>last-command</code> when the command finishes (unless the command specified a prefix argument for the following command). </p> <p>Some commands set this variable during their execution, as a flag for whatever command runs next. In particular, the functions for killing text set <code>this-command</code> to <code>kill-region</code> so that any kill commands immediately following will know to append the killed text to the previous kill. </p>
</dd>
</dl> <p>If you do not want a particular command to be recognized as the previous command in the case where it got an error, you must code that command to prevent this. One way is to set <code>this-command</code> to <code>t</code> at the beginning of the command, and set <code>this-command</code> back to its proper value at the end, like this: </p> <div class="example"> <pre class="example">(defun foo (args…)
(interactive …)
(let ((old-this-command this-command))
(setq this-command t)
<span class="roman">…do the work…</span>
(setq this-command old-this-command)))
</pre>
</div> <p>We do not bind <code>this-command</code> with <code>let</code> because that would restore the old value in case of error—a feature of <code>let</code> which in this case does precisely what we want to avoid. </p> <dl> <dt id="this-original-command">Variable: <strong>this-original-command</strong>
</dt> <dd><p>This has the same value as <code>this-command</code> except when command remapping occurs (see <a href="remapping-commands">Remapping Commands</a>). In that case, <code>this-command</code> gives the command actually run (the result of remapping), and <code>this-original-command</code> gives the command that was specified to run but remapped into another command. </p></dd>
</dl> <dl> <dt id="current-minibuffer-command">Variable: <strong>current-minibuffer-command</strong>
</dt> <dd><p>This has the same value as <code>this-command</code>, but is bound recursively when entering a minibuffer. This variable can be used from minibuffer hooks and the like to determine what command opened the current minibuffer session. </p></dd>
</dl> <dl> <dt id="this-command-keys">Function: <strong>this-command-keys</strong>
</dt> <dd>
<p>This function returns a string or vector containing the key sequence that invoked the present command. Any events read by the command using <code>read-event</code> without a timeout get tacked on to the end. </p> <p>However, if the command has called <code>read-key-sequence</code>, it returns the last read key sequence. See <a href="key-sequence-input">Key Sequence Input</a>. The value is a string if all events in the sequence were characters that fit in a string. See <a href="input-events">Input Events</a>. </p> <div class="example"> <pre class="example">(this-command-keys)
;; <span class="roman">Now use <kbd>C-u C-x C-e</kbd> to evaluate that.</span>
⇒ "^X^E"
</pre>
</div> </dd>
</dl> <dl> <dt id="this-command-keys-vector">Function: <strong>this-command-keys-vector</strong>
</dt> <dd>
<p>Like <code>this-command-keys</code>, except that it always returns the events in a vector, so you don’t need to deal with the complexities of storing input events in a string (see <a href="strings-of-events">Strings of Events</a>). </p>
</dd>
</dl> <dl> <dt id="clear-this-command-keys">Function: <strong>clear-this-command-keys</strong> <em>&optional keep-record</em>
</dt> <dd><p>This function empties out the table of events for <code>this-command-keys</code> to return. Unless <var>keep-record</var> is non-<code>nil</code>, it also empties the records that the function <code>recent-keys</code> (see <a href="recording-input">Recording Input</a>) will subsequently return. This is useful after reading a password, to prevent the password from echoing inadvertently as part of the next command in certain cases. </p></dd>
</dl> <dl> <dt id="last-nonmenu-event">Variable: <strong>last-nonmenu-event</strong>
</dt> <dd>
<p>This variable holds the last input event read as part of a key sequence, not counting events resulting from mouse menus. </p> <p>One use of this variable is for telling <code>x-popup-menu</code> where to pop up a menu. It is also used internally by <code>y-or-n-p</code> (see <a href="yes_002dor_002dno-queries">Yes-or-No Queries</a>). </p>
</dd>
</dl> <dl> <dt id="last-command-event">Variable: <strong>last-command-event</strong>
</dt> <dd>
<p>This variable is set to the last input event that was read by the command loop as part of a command. The principal use of this variable is in <code>self-insert-command</code>, which uses it to decide which character to insert. </p> <div class="example"> <pre class="example">last-command-event
;; <span class="roman">Now use <kbd>C-u C-x C-e</kbd> to evaluate that.</span>
⇒ 5
</pre>
</div> <p>The value is 5 because that is the <acronym>ASCII</acronym> code for <kbd>C-e</kbd>. </p>
</dd>
</dl> <dl> <dt id="last-event-frame">Variable: <strong>last-event-frame</strong>
</dt> <dd>
<p>This variable records which frame the last input event was directed to. Usually this is the frame that was selected when the event was generated, but if that frame has redirected input focus to another frame, the value is the frame to which the event was redirected. See <a href="input-focus">Input Focus</a>. </p> <p>If the last event came from a keyboard macro, the value is <code>macro</code>. </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/Command-Loop-Info.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Command-Loop-Info.html</a>
</p>
</div>
|