Last year I wrote about abo-abo’s screencast demonstrating a bit of his refactoring workflow. I just ran across it again and it’s so great I want to mention it once more in case some of you haven’t seen it.
The video shows how he does a small refactoring of some code in his Avy library. The basic plan is
- Use swiper to locate every instance of the code to be changed
- Call
ivy-occur
to save the swiper results to a separate buffer - Switch to the occur buffer
- Start a keyboard macro
- Select the first item in the occur buffer
- Perform the refactoring of the first match (we’re now in the code buffer)
- Switch back to the occur buffer, move to the next item, and end the macro
- Run the macro on the rest of the items.
Notice how he is switching buffers while recording the macro. This is a much more efficient method than, say,
- Search for the first match
- Perform the refactoring while recording the macro
- End the macro and save it
- Search for the next match
- Run the saved macro if not done
- Goto 4
Actually, abo-abo also collects some information along the way that he uses to set up defaults. He puts this in a third buffer so his macro is actually dealing with three buffers. This is a brilliant use of keyboard macros and a tour de force in refactoring technique. It’s worth watching for the entertainment value alone. It’s only 10 minutes so there’s no excuse for missing out.