elisp: Keyboard Macros
20.16 Keyboard Macros
=====================
A “keyboard macro” is a canned sequence of input events that can be
considered a command and made the definition of a key. The Lisp
representation of a keyboard macro is a string or vector containing the
events. Don’t confuse keyboard macros with Lisp macros (
Macros).
-- Function: execute-kbd-macro kbdmacro &optional count loopfunc
This function executes KBDMACRO as a sequence of events. If
KBDMACRO is a string or vector, then the events in it are executed
exactly as if they had been input by the user. The sequence is
_not_ expected to be a single key sequence; normally a keyboard
macro definition consists of several key sequences concatenated.
If KBDMACRO is a symbol, then its function definition is used in
place of KBDMACRO. If that is another symbol, this process
repeats. Eventually the result should be a string or vector. If
the result is not a symbol, string, or vector, an error is
signaled.
The argument COUNT is a repeat count; KBDMACRO is executed that
many times. If COUNT is omitted or ‘nil’, KBDMACRO is executed
once. If it is 0, KBDMACRO is executed over and over until it
encounters an error or a failing search.
If LOOPFUNC is non-‘nil’, it is a function that is called, without
arguments, prior to each iteration of the macro. If LOOPFUNC
returns ‘nil’, then this stops execution of the macro.
Reading One Event, for an example of using
‘execute-kbd-macro’.
-- Variable: executing-kbd-macro
This variable contains the string or vector that defines the
keyboard macro that is currently executing. It is ‘nil’ if no
macro is currently executing. A command can test this variable so
as to behave differently when run from an executing macro. Do not
set this variable yourself.
-- Variable: defining-kbd-macro
This variable is non-‘nil’ if and only if a keyboard macro is being
defined. A command can test this variable so as to behave
differently while a macro is being defined. The value is ‘append’
while appending to the definition of an existing macro. The
commands ‘start-kbd-macro’, ‘kmacro-start-macro’ and
‘end-kbd-macro’ set this variable—do not set it yourself.
The variable is always local to the current terminal and cannot be
buffer-local. Multiple Terminals.
-- Variable: last-kbd-macro
This variable is the definition of the most recently defined
keyboard macro. Its value is a string or vector, or ‘nil’.
The variable is always local to the current terminal and cannot be
buffer-local. Multiple Terminals.
-- Variable: kbd-macro-termination-hook
This normal hook is run when a keyboard macro terminates,
regardless of what caused it to terminate (reaching the macro end
or an error which ended the macro prematurely).