Книга: Learning GNU Emacs, 3rd Edition
6.9 Executing Macros on a Region
6.9 Executing Macros on a Region
A special command lets you execute a macro on each line in a region. How frequently do you encounter an email with text that you want to yank, but that is quoted several indentation levels? Of course, we can think of several ways to delete the indentation quickly, but a line-oriented macro is a quick approach too. You define the macro and execute it on a region by typing C-x C-k r (for apply-macro-to-region-lines). Remember that earlier we said that macros should set themselves up to repeat? This command is different because it expects to work on one line at a time. You don't want to set it up to repeat by moving to the next line; it does that automatically.
Table 6-5 shows a quick line-oriented macro that deletes indentation marks from text quoted in an email or newsgroup message.
Table 6-5. Macro for deleting indentation marks
Keystrokes | Action |
---|---|
F3 | Start the macro definition. |
C-a | Move to the beginning of the line. |
M-f | Move forward one word. |
M-b | Move to the beginning of this word. |
C-Space | Set the mark. |
C-a | Move to the beginning of the line. |
C-w | Delete the extraneous indentation characters. |
F4 | End the macro definition. |
Initial state:
Text indented at various levels (Mac OS X).
Mark the text as a region, move to the beginning of the region, then type: C-x C-k r
Indentation is deleted (Mac OS X).
- A Macro Revolution
- 6.1 Defining a Macro
- 6.2 Tips for Creating Good Macros
- 6.3 A More Complicated Macro Example
- 6.4 Editing a Macro
- 6.5 The Macro Ring
- 6.6 Binding Your Macro to a Key
- 6.7 Naming, Saving, and Executing Your Macros
- 6.8 Building More Complicated Macros
- 6.9 Executing Macros on a Region
- 6.10 Beyond Macros
- 6.10 Beyond Macros
- CHAPTER 33 Writing and Executing a Shell Script
- 5.4.1. The *__initcall Macros
- 9.3.1. Regions and Segments
- 14.3.4. Useful Kernel gdb Macros
- 3.3.1 Executing from ROM Using RAM for Data
- 3.3.2 Executing from RAM after Image Transfer from ROM
- 3.3.3 Executing from RAM after Image Transfer from Host
- #region and #endregion
- 6.2 Tips for Creating Good Macros
- 11.3.1 Buffers, Text, and Regions
- Chapter 6. Writing Macros