Beyond Macros

Macros are an extremely 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 13 covers the basics of writing LISP functions.

Table 10-1 summarizes the macro commands we discussed in this chapter.

Table 11-1. Macro Commands

Keystrokes

Command Name

Action

C-x (

start-kbd-macro

Start macro definition.

C-x )

end-kbd-macro

End macro definition.

C-x e

call-last-kbd-macro

Execute last macro defined.

ESC n C-x e

digit-argument and call-last-kbd-macro

Execute the last macro defined n times.

C-u C-x (

universal-argument; start-kbd-macro

Execute the last macro defined and then it allows you to add keystrokes to it.

(none)

name-last-kbd-macro

Name the last macro you created (a preface to saving it).

(none)

insert-last-keyboard-macro

Insert the macro you named into a file.

(none)

load-file

Load a file containing command ...

Get Learning GNU Emacs, Second 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.