Next: Defining Commands, Previous: Command Loop, Up: Command Loop [Contents][Index]
The command loop in SXEmacs is a standard event loop, reading events
one at a time with next-event
and handling them with
dispatch-event
. An event is typically a single user action, such
as a keypress, mouse movement, or menu selection; but they can also be
notifications from the window system, informing SXEmacs that (for
example) part of its window was just uncovered and needs to be redrawn.
See Events. Pending events are held in a first-in, first-out list
called the event queue: events are read from the head of the list,
and newly arriving events are added to the tail. In this way, events
are always processed in the order in which they arrive.
dispatch-event
does most of the work of handling user actions.
The first thing it must do is put the events together into a key
sequence, which is a sequence of events that translates into a command.
It does this by consulting the active keymaps, which specify what the
valid key sequences are and how to translate them into commands.
See Key Lookup, for information on how this is done. The result of
the translation should be a keyboard macro or an interactively callable
function. If the key is M-x, then it reads the name of another
command, which it then calls. This is done by the command
execute-extended-command
(see Interactive Call).
To execute a command requires first reading the arguments for it.
This is done by calling command-execute
(see Interactive Call). For commands written in Lisp, the interactive
specification says how to read the arguments. This may use the prefix
argument (see Prefix Command Arguments) or may read with prompting
in the minibuffer (see Minibuffers).
For example, the command find-file
has an interactive
specification which says to read a file name using the minibuffer. The
command’s function body does not use the minibuffer; if you call this
command from Lisp code as a function, you must supply the file name
string as an ordinary Lisp function argument.
If the command is a string or vector (i.e., a keyboard macro) then
execute-kbd-macro
is used to execute it. You can call this
function yourself (see Keyboard Macros).
To terminate the execution of a running command, type C-g. This character causes quitting (see Quitting).
The editor command loop runs this normal hook before each command. At
that time, this-command
contains the command that is about to
run, and last-command
describes the previous command.
See Hooks.
The editor command loop runs this normal hook after each command. (In
FSF Emacs, it is also run when the command loop is entered, or
reentered after an error or quit.) At that time,
this-command
describes the command that just ran, and
last-command
describes the command before that. See Hooks.
Quitting is suppressed while running pre-command-hook
and
post-command-hook
. If an error happens while executing one of
these hooks, it terminates execution of the hook, but that is all it
does.
Next: Defining Commands, Previous: Command Loop, Up: Command Loop [Contents][Index]