Keyboard Macros

jed 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 CTRL-X ( if emacs.sl is loaded. To stop recording the keystrokes, enter CTRL-X ). Then to ``execute'' the macro, press CTRL-X E. 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 CTRL-G key.

One nice feature jed includes is the macro_query function. That is, while defining a macro, the key sequence CTRL-X Q will cause jed to issue the prompt Enter String: 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, jed will prompt for a NEW string to be inserted.

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:

      Ctrl-X (                      (begin macro)
      Ctrl-E                        (goto end of line)
      ESC                           (trim whitespace)
      Down Arrow                    (go down one line)
      Ctrl-X )                      (end macro)

Now the macro has been defined. So move to the top of the buffer and execute it 32000 times:

      ESC <                         (top of buffer)
      ESC 3 2 0 0 0                 (repeat next command 32000 times
      Ctrl-X e                      (execute macro)
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.