Go to the first, previous, next, last section, table of contents.


Information from the Command Loop

The editor command loop sets several Lisp variables to keep status records for itself and for commands that are run.

Variable: last-command
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.

The value is copied from this-command when a command returns to the command loop, except when the command specifies 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.

Variable: this-command
This variable records the name of the command now being executed by the editor command loop. Like 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 specifies 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)))

Function: this-command-keys
This function returns a string or vector containing the key sequence that invoked the present command, plus any previous commands that generated the prefix argument for this command. The value is a string if all those events were characters. See section Input Events.

(this-command-keys)
;; Now use C-u C-x C-e to evaluate that.
     => "^U^X^E"

Variable: last-nonmenu-event
This variable holds the last input event read as part of a key sequence, not counting events resulting from mouse menus.

One use of this variable is to figure out a good default location to pop up another menu.

Variable: last-command-event
Variable: last-command-char
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 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.

Variable: last-event-frame
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 section Input Focus.


Go to the first, previous, next, last section, table of contents.