HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/share/doc/jed/html/jed013.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<meta name="generator" content="hevea 2.35">
<link rel="stylesheet" type="text/css" href="jed.css">
<title>Keyboard Macros</title>
</head>
<body >
<a href="jed012.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="jed014.html"><img src="next_motif.svg" alt="Next"></a>
<hr>
<h2 id="sec30" class="section">12&#X2003;Keyboard Macros</h2>
<p><span style="font-weight:bold">jed</span> is able to record a series of keystrokes from the terminal and replay
them. The saved series of keystrokes is known as a keyboard macro. To
begin a keyboard macro, simply enter the begin keyboard macro key sequence
which is bound to <span style="font-variant:small-caps">Ctrl-X (</span> if <code class="verb">emacs.sl</code> is loaded. To stop
recording the keystrokes, enter <span style="font-variant:small-caps">Ctrl-X )</span>. Then to &#X201C;execute&#X201D; the
macro, press <span style="font-variant:small-caps">Ctrl-X e</span>. Please note that it is illegal to execute a
macro while defining one and doing so generates an error. A macro can be
aborted at anytime by pressing the <span style="font-variant:small-caps">Ctrl-G</span> key.</p><p>One nice feature <span style="font-weight:bold">jed</span> includes is the <code class="verb">macro_query</code> function. That
is, while defining a macro, the key sequence <span style="font-variant:small-caps">Ctrl-X q</span> will cause
<span style="font-weight:bold">jed</span> to issue the prompt <span style="font-family:monospace">Enter String:</span> in the minibuffer. Any
string that is entered will be inserted into the buffer and the process of
defining the macro continues. Every time the macro is executed, <span style="font-weight:bold">jed</span>
will prompt for a NEW string to be inserted.</p><p>Any time an error is generated, the process of defining the macro is
aborted as well as execution of the macro. This is very useful and may be
exploited often. For example, suppose you want to trim excess whitespace
from the end of ALL lines in a buffer. Let us also suppose that the
number of lines in the buffer is less than 32000. Then consider the
following keystrokes:
</p><pre class="verbatim">      Ctrl-X (                      (begin macro)
      Ctrl-E                        (goto end of line)
      ESC                           (trim whitespace)
      Down Arrow                    (go down one line)
      Ctrl-X )                      (end macro)
</pre><p>Now the macro has been defined. So move to the top of the buffer and
execute it 32000 times:
</p><pre class="verbatim">      ESC &lt;                         (top of buffer)
      ESC 3 2 0 0 0                 (repeat next command 32000 times
      Ctrl-X e                      (execute macro)
</pre><p>
If the buffer has less than 32000 lines, the end of the buffer will be
reached and an error will be generated aborting the execution of the macro.</p>
<hr>
<a href="jed012.html"><img src="previous_motif.svg" alt="Previous"></a>
<a href="index.html"><img src="contents_motif.svg" alt="Up"></a>
<a href="jed014.html"><img src="next_motif.svg" alt="Next"></a>
</body>
</html>