Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 13: Macros |  | Previous HourNext Hour
Sections in this Hour: |  |  |  |

## Editing a Macro

After you have recorded a macro, you might find that it is erroneous or that it would be nice if it went a bit farther. Starting at the later requirement, this is easy: Press C-u C-x (--start-kbd-macro with a C-u prefix--instead of C-x ( to start recording the macro.

To edit a macro, you must press C-x C-k (edit-kbd-macro). This asks you which macro to edit in the minibuffer. You have the following possibilities:

- C-x e--This edits the most-recently defined macro; that is, the one that is available by pressing C-x e.

- M-x--This enables you to edit a macro that you have named (as described in task "Naming a Macro"). When you press M-x, Emacs asks you for the name of the macro in the minibuffer.

- C-h l--This lets you use the latest 100 keystrokes as the macro. When you save your editing, it is saved as the macro available through C-x e.

Note - The key sequence C-h l comes from the command with the given binding (view-lossage). This command enables you to see the last 100 keystrokes, so you can see what you did. Now that you have learned to use edit-kbd-macro, you might find this interface more useful than the one from C-h l.

Caution - This key sequence, unfortunately, doesn't work if you have redefined C-h l to a command other than view-lossage, which is in fact what the package ehelp does.

- Keys--This tells you that you can press a key sequence that is bound to a macro. It is the macro to which these keys are bound that is edited.

When you have selected the macro to edit, the buffer shown in Figure 13.3 appears.

Figure 13.3
Editing the macro.

In the first two lines, you see how to exit this buffer again and what the content of the macro was when you entered this buffer (in case you suddenly are in doubt whether your changes are correct). As it says, you can press either C-c C-c to save your changes to the macro you edit or C-x k to discard them. Both actions delete the buffer and restore the original one.

The following two lines tell you which macro you're editing and which key it is bound to, if any.

Finally comes the content of the macro. In the left column is the content of the macro, and in the right column is the Lisp function that the keys execute. If you do not understand a word of what the right column says, don't bother. Don't delete the two semicolons without deleting the rest of the line. It should be simple to read what it says. Ordinary inserted characters are shown the way they were inserted. Examples of this include Name:, Street:, and City:. Another alternative would be text that describes special keys. This includes SPC for a space, RET for the return key, DEL for the delete button, and <left> for the left-arrow key. Finally a keypress can be shown (such as C-u C-x q in the example).

You can edit this buffer as you would any other buffer. The only difference is that when you press C-c C-c, the content of the buffer will be used to define a macro.

When you edit this buffer, you can press C-c C-q to insert a keypress into your macro. If you want to move point one character to the left, you should press C-c C-q and then the left-arrow key. Ordinary text is inserted verbatim, thus if you want to change the word Name to First Name , insert the word First at the line before Name, followed by a linebreak and the text SPC.

Caution - You should be aware that using the Spacebar does not insert a space. Instead you should type SPC.

Sams Teach Yourself Emacs in 24 Hours |  | ContentsIndex
Hour 13: Macros |  | Previous HourNext Hour
Sections in this Hour: |  |  |  |

© Copyright Macmillan USA. All rights reserved.