Unduly-noted is a new Emacs user but that didn’t stop him from figuring out how to leverage Emacs to streamline his workflow. The TL;DR is that he wanted to import lectures and ancillary data from a course he was taking into Emacs. The lectures and extra data were in separate directories on the course Website and were not named in a way that facilitated sorting them in his Dired listing.
His first solution was to import and rename them manually with a numerical prefix to indicate the lecture number but that was labor intensive and tedious so he moved to using keyboard macros for the renaming but he still needed to manually change the numerical prefix. His final solution was to put the numerical prefix in a register, insert the value into the new name, and then increment the register value. It’s a nice solution that makes accomplishing his task much easier.
Somehow, long ago, I got it into my head that using a register in a keyboard macro required a special keyboard macro command. Unduly-noted’s post makes it clear that that’s not true. You simply use registers the same way you would if you weren’t in a macro:
- Set the initial value before starting the macro.
- Insert the value of the register in the appropriate place.
- Increment the value in the macro.
It’s a nice post that demonstrates how to combine keyboard macros and registers to solve a simple problem. As usual, knowing just a little bit about Emacs makes it easy to automate repetitive and mundane tasks.