Revisiting abo-abo's Refactoring Video

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

  1. Use swiper to locate every instance of the code to be changed
  2. Call ivy-occur to save the swiper results to a separate buffer
  3. Switch to the occur buffer
  4. Start a keyboard macro
  5. Select the first item in the occur buffer
  6. Perform the refactoring of the first match (we’re now in the code buffer)
  7. Switch back to the occur buffer, move to the next item, and end the macro
  8. 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,

  1. Search for the first match
  2. Perform the refactoring while recording the macro
  3. End the macro and save it
  4. Search for the next match
  5. Run the saved macro if not done
  6. 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.

This entry was posted in General and tagged . Bookmark the permalink.
  • Phil

    Cross-buffer keyboard macro recordings were a real "Ah ha!" moment for me back in the day. I hadn't used macros much at all before then, but that delightful little insight really opened my eyes to how powerful they are, and got me using them regularly (after which I started noticing all kinds of ways to use them for little ad-hoc edits too).