The incomparable Mickey of Mastering Emacs fame has a really nice post on the power of keyboard macros. Most of us, even experienced Emacs users, tend to think of keyboard macros as a way of automating repetitive text editing but they’re actually much more powerful than that.
The key is that when you’re recording a macro, Emacs records everything you do. Thus, to use one of Mickey’s examples, it’s a simple matter to record your actions while you’re configuring your Emacs window setup and then use that macro whenever you want that particular setup in the future. Of course, to do that you need some way of persisting your keyboard macros across Emacs sessions.
That’s easy to do and Mickey explains the process, including how to turn the keyboard macro into a function that you can call in the normal way with Meta+x macro-name
. Mickey also explains how to edit, debug, and step through a keyboard macro.
As Mickey points out at the beginning of his post, Emacs has all sorts of users and many of them don’t know or want to learn Elisp. Still, they, like the rest of us, have tasks they’d like to automate. Rather than having to learn Elisp, a simple keyboard macro will often provide just what’s needed.
All Emacs users should definitely read through Mickey’s post, probably more than once. You might even want to bookmark it so you can easily retrieve the details of working with keyboard macros.