The editor command loop sets several Lisp variables to keep status records for itself and for commands that are run.
The value is copied from this-command
when a command returns to
the command loop, except when the command has specified a prefix
argument for the following command.
This variable is always local to the current terminal and cannot be buffer-local. See section Multiple Displays.
last-command
,
but never altered by Lisp programs.
last-command
, it is normally a symbol
with a function definition.
The command loop sets this variable just before running a command, and
copies its value into last-command
when the command finishes
(unless the command specified a prefix argument for the following
command).
Some commands set this variable during their execution, as a flag for
whatever command runs next. In particular, the functions for killing text
set this-command
to kill-region
so that any kill commands
immediately following will know to append the killed text to the
previous kill.
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 this-command
to t
at the
beginning of the command, and set this-command
back to its proper
value at the end, like this:
(defun foo (args...) (interactive ...) (let ((old-this-command this-command)) (setq this-command t) ...do the work... (setq this-command old-this-command)))
We do not bind this-command
with let
because that would
restore the old value in case of error--a feature of let
which
in this case does precisely what we want to avoid.
(this-command-keys) ;; Now use C-u C-x C-e to evaluate that. => "^U^X^E"
this-command-keys
, except that it always returns
the events in a vector, so you do never need to deal with the complexities
of storing input events in a string (see section Putting Keyboard Events in Strings).
One use of this variable is for telling x-popup-menu
where to pop
up a menu. It is also used internally by y-or-n-p
(see section Yes-or-No Queries).
self-insert-command
, which uses it to decide which
character to insert.
last-command-event ;; Now use C-u C-x C-e to evaluate that. => 5
The value is 5 because that is the ASCII code for C-e.
The alias last-command-char
exists for compatibility with
Emacs version 18.
Go to the first, previous, next, last section, table of contents.