Beyond Macros
Macros are an important tool for streamlining repetitive editing. They let you write your own commands for performing complex tasks without needing to know anything more than you already know: the basic Emacs commands for moving around and manipulating text. Even if you're an Emacs novice, you should be able to use macros with little difficulty.
However, Emacs is almost infinitely flexible, and macros cannot do everything. In many situations, there's no substitute for writing a Lisp function that does exactly what you want. If you know Lisp or would like to learn some, you can write your own Lisp functions to do more complex tasks than keyboard macros can handle. Chapter 11 covers the basics of writing Lisp functions.
Table 6-6 summarizes macro commands.
Table 6-6. Macro commands
Keystrokes |
Command name |
Action |
---|---|---|
C-x ( |
kmacro-start-macro |
Start macro definition. |
F3 |
kmacro-start-macro-or-insert-counter |
Start macro definition. If pressed while defining a macro, insert a counter. |
C-x ) |
kmacro-end-macro |
End macro definition. |
F4 |
kmacro-end-or-call-macro |
End macro definition (if definition is in progress) or invoke last keyboard macro. |
C-x e |
kmacro-end-and-call-macro |
Execute last keyboard macro defined. Can type e to repeat macro. |
C-x C-k n |
name-last-kbd-macro |
Name the last macro you created (before saving it). |
(none) |
insert-kbd-macro |
Insert the macro you named into a file. |
(none) |
macroname |
Execute a named keyboard macro. ... |
Get Learning GNU Emacs, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.