summaryrefslogtreecommitdiff
path: root/devdocs/elisp/keyboard-macros.html
blob: ed64c45fc2dc116209fb7f3730778440d786690b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 <h3 class="section">Keyboard Macros</h3>  <p>A <em>keyboard macro</em> 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 (see <a href="macros">Macros</a>). </p> <dl> <dt id="execute-kbd-macro">Function: <strong>execute-kbd-macro</strong> <em>kbdmacro &amp;optional count loopfunc</em>
</dt> <dd>
<p>This function executes <var>kbdmacro</var> as a sequence of events. If <var>kbdmacro</var> 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 <em>not</em> expected to be a single key sequence; normally a keyboard macro definition consists of several key sequences concatenated. </p> <p>If <var>kbdmacro</var> is a symbol, then its function definition is used in place of <var>kbdmacro</var>. 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. </p> <p>The argument <var>count</var> is a repeat count; <var>kbdmacro</var> is executed that many times. If <var>count</var> is omitted or <code>nil</code>, <var>kbdmacro</var> is executed once. If it is 0, <var>kbdmacro</var> is executed over and over until it encounters an error or a failing search. </p> <p>If <var>loopfunc</var> is non-<code>nil</code>, it is a function that is called, without arguments, prior to each iteration of the macro. If <var>loopfunc</var> returns <code>nil</code>, then this stops execution of the macro. </p> <p>See <a href="reading-one-event">Reading One Event</a>, for an example of using <code>execute-kbd-macro</code>. </p>
</dd>
</dl> <dl> <dt id="executing-kbd-macro">Variable: <strong>executing-kbd-macro</strong>
</dt> <dd><p>This variable contains the string or vector that defines the keyboard macro that is currently executing. It is <code>nil</code> 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. </p></dd>
</dl> <dl> <dt id="defining-kbd-macro">Variable: <strong>defining-kbd-macro</strong>
</dt> <dd>
<p>This variable is non-<code>nil</code> 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 <code>append</code> while appending to the definition of an existing macro. The commands <code>start-kbd-macro</code>, <code>kmacro-start-macro</code> and <code>end-kbd-macro</code> set this variable—do not set it yourself. </p> <p>The variable is always local to the current terminal and cannot be buffer-local. See <a href="multiple-terminals">Multiple Terminals</a>. </p>
</dd>
</dl> <dl> <dt id="last-kbd-macro">Variable: <strong>last-kbd-macro</strong>
</dt> <dd>
<p>This variable is the definition of the most recently defined keyboard macro. Its value is a string or vector, or <code>nil</code>. </p> <p>The variable is always local to the current terminal and cannot be buffer-local. See <a href="multiple-terminals">Multiple Terminals</a>. </p>
</dd>
</dl> <dl> <dt id="kbd-macro-termination-hook">Variable: <strong>kbd-macro-termination-hook</strong>
</dt> <dd><p>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). </p></dd>
</dl><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Keyboard-Macros.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Keyboard-Macros.html</a>
  </p>
</div>