Awesome Computers

Emacs Occur

In which I write about a cool trick in Emacs ‘occur’ package.

I love Emacs. It’s a great text editor and platform for doing all sorts of things. One of the ways that it makes a great editing environment is that things are extensible, often live in the environment. One of the things I used to use is a package called “ioccur“, this allowed you to edit occurrences of a specified text across the document. This mirrored a built-in function called “Occur“, which showed you each line or instance of the occurrence across the document. The biggest problem was that once you found stuff, you had to swap back and forth between the list and the actual document. I have since learned about the ability to edit the document right from the “Occur” results.

Once you have a list of items, you can press e to enter edit mode. Each line becomes linked to their buffer line and you can make edits to whatever you want and they’ll be reflected, live. Once you’re done, you can return to the “Occur” mode (which allows you to do more) by pressing C-c C-c (a common Emacs ‘complete’ command).

Here is the feature in action:

Here is the effect in action, inside my .profile file.

By Nathan

Hello! My name is Nathan and I'm a technologist living and working in the south east. I love breaking crap and fixing it. I tend to break more than I fix. When I'm not breaking and fixing stuff, I'm playing games with my son or going to Disney with my family. I strongly support open source software, hardware and greater transparency in government.