This section describes how to "peek ahead" at events without using
them up, how to check for pending input, and how to discard pending
input. See also the function read-passwd
(see section Reading a Password).
The variable is needed because in some cases a function reads an event and then decides not to use it. Storing the event in this variable causes it to be processed normally, by the command loop or by the functions to read command input.
For example, the function that implements numeric prefix arguments reads any number of digits. When it finds a non-digit event, it must unread the event so that it can be read normally by the command loop. Likewise, incremental search uses this feature to unread events with no special meaning in a search, because these events should exit the search and then execute normally.
The reliable and easy way to extract events from a key sequence so as to
put them in unread-command-events
is to use
listify-key-sequence
(see section Putting Keyboard Events in Strings).
Normally you add events to the front of this list, so that the events most recently unread will be reread first.
unread-command-events
.
This variable is mostly obsolete now that you can use
unread-command-events
instead; it exists only to support programs
written for Emacs versions 18 and earlier.
t
if
there is available input, nil
otherwise. On rare occasions it
may return t
when no input is available.
In the example below, the Lisp program reads the character 1,
ASCII code 49. It becomes the value of last-input-event
,
while C-e (we assume C-x C-e command is used to evaluate
this expression) remains the value of last-command-event
.
(progn (print (read-char)) (print last-command-event) last-input-event) -| 49 -| 5 => 49
The alias last-input-char
exists for compatibility with
Emacs version 18.
nil
.
In the following example, the user may type a number of characters right
after starting the evaluation of the form. After the sleep-for
finishes sleeping, discard-input
discards any characters typed
during the sleep.
(progn (sleep-for 2) (discard-input)) => nil
Go to the first, previous, next, last section, table of contents.