Find Org Files

Howard Abrams has a nifty idea. Open an Org file by its file name, title, or the tags it contains. If, like me, the majority of the files you deal with are Org files this make a lot of sense. When you call org-find-file instead of find-file, you get a list that contains the file name, title, and tags. Since it’s mediated by completing-read you can narrow down the choices in the usual way. Once you make a choice, find-file is called with the file name from the chosen entry.

The design of the command is interesting. Rather than build something like a TAGS file for use by the command, everything happens dynamically in real time. Abrams leverages the speed of the modern grep ripgrep to build the completing-read selection list on the fly. Of course, it’s a little more complicated than that. First, ripgrep is called to gather the titles and then it is called again to gather the tags in each of the files in the target directory.

Most of Abram’s code is concerned with putting together the information and formatting each entry into a nice looking line for the user to select from. The use of ripgrep makes most of it simple. The main difficulty is gathering the tags because they can appear in an Org file in a couple of ways—see Abrams’ post for the details.

If you’re interested in playing around with his code, it’s available in his GitHub repository. It’s a nice piece of engineering and well worth studying for its ideas.

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