Completing Org Links

Jeremy Friesen has an interesting post that may teach you a couple of things you didn’t know. Friesen uses Org mode a lot in his writing and everything he writes and has lots of links—both standard and customized—in that writing. His problem is that he often wants to complete a word or symbol to a link that is already in the buffer.

On the one hand, I’m not at all interested in this post because I try never to link to something more than once in a single post. On the other hand, the post is still interesting to me because it provides a good go-by for how to obtain a list of (Org) links in the current buffer. That turns out to be harder and simpler than you might think. The solution is not to cycle through the buffer looking for the appropriate regex. Rather, the solution involves using org-element-map to find the links and generate propertized strings of the results. It’s a nice example of dealing with an Org buffer without falling back on regexes.

Friesen also presents some other code that shows how he does the actually completion if your interested in duplicating his workflow but even if you’re not the post has lots of good technical information. Even if you don’t have custonized links, you might find it useful.

UPDATE [2023-05-09 Tue 14:28]: In a subsequent post, Friesen explains his need to link to a resource multiple times.

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