Книга: Learning GNU Emacs, 3rd Edition
6.5 The Macro Ring
6.5 The Macro Ring
Although our latest macro is interesting, it's not really a general purpose macro. It is a temporary solution to a one-time problem. It saves you some work, but it isn't general enough to save and use again. On the other hand, our macro to transpose names is generally useful. We'd like to use it again. We'd like to bind it to a key. But it is no longer the "latest" keyboard macro.
As we mentioned earlier, Emacs has a macro ring much like the infamous kill ring. It's useful in the case we've just described, but it's also useful because of the fragility of the macro definition process. You create a macro and make a wrong move that rings the bell, and your macro is canceled. It's fairly easy to create a macro that does nothing. Perhaps the macro that you just created was wonderful, and this new nonfunctional nothing macro has supplanted it. Again, the macro ring is the solution. To delete a macro from the ring, type C-x C-k C-d (for kmacro-delete-ring-head). This deletes the most recently defined keyboard macro.
What if you want to swap the positions of two macros? Instead, type C-x C-k C-t (for kmacro-swap-ring). This transposes macros 1 and 2.
In a more general sense, you can cycle to the previously defined macro by typing C-c C-k C-p (for kmacro-cycle-ring-previous). To move the ring the other way, type C-x C-k C-n (for kmacro-cycle-ring-next). The familiar C-p for previous and C-n for next bindings are appended to the general macro keyboard prefix C-x C-k.
Before we can work with the transpose names macro, we must either define it again or, if you've been working through our examples, type C-x C-k C-p to move to the previous macro.
- 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
- Building the sendmail.cf File
- 5.3.1. The __setup Macro
- Local macro definitions
- 6.2 Tips for Creating Good Macros
- Macro Parameters
- 4.4.4 The Dispatcher
- About the author
- Chapter 7. The state machine
- Chapter 8. Saving and restoring large rule-sets
- Chapter 5 Installing and Configuring VirtualCenter 2.0
- Appendix E. Other resources and links
- IP filtering terms and expressions