A Real World Use Case of Occur

Protesilaos Stavrou has posted a very nice video on using editable occur to solve a real life editing problem. The basic strategy is to use occur to locate all the occurrences of the problem to be fixed, type e in the occur buffer to make it editable, and then use a keyboard macro or other means of your choice to make your changes. The changes are, of course, reflected in the original buffer and are written to disk when you exit the edit mode of occur.

This is very reminiscent of abo-abo’s refactoring workflow that I wrote about back in 2015. The idea is basically the same: use some sort of grep-like operation to get all the relevant lines in a buffer, make the buffer editable, make your changes, and write those changes back to the file(s) they occurred in.

If you like this sort of thing, abo-abo has a video demonstrating a workflow similar to Stavrou’s. It is, I think, hard to find better examples of the awesomeness of Emacs’ editing capabilities than these videos by Stavrou and abo-abo.

As a final note, I was pleased to discover that you can make an occur buffer editable simply by pressing e. I always did it by toggling the read-only state with Ctrl+x Ctrl+q. I’m not sure why I didn’t know about using e since I use the facility all the time but then I’m always learning something new about Emacs that you’d think I would already know.

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