Searching any Web link within a Org library using org-ql

Jon Snader of Irreal recently made a few blog post about using Emacs as “bookmark launcher”. You can read them here and here. Those methods were working well, but I was missing something.

I am working with Org a lot these days. Not for literate programming as I normally do, but mainly using Org-Roam to build my technical knowledge base, to write meeting debriefs and all kind of other planning tasks.  In that process, I do add a lot of reference to different websites in several different Org files.

What those blog posts from Jon triggered in me is a need to be able to easily search for this disparate links scattered across hundred of Org files. It was on my todo, but I was lacking time to dedicate to this.

But, for some reason, I took the opportunity to take 15 minutes to learn about org-ql today. While looking at its codebase, I quickly noticed two functions: org-ql-open-link which uses Vertico to search for links within the current Org buffer. A few minutes later I noticed the org-ql-find-in-agenda which find anything within all the files in the agenda file.

org-ql-open-link-in-agenda

Within a few minutes, I merged those two functions to create a new org-ql-open-link-in-agenda which do exactly what I was looking for: searching within all my Org files for links, and leveraging Vertico or Helm to expose them to me. The other neat thing is that org-ql-open-link does put some context in the search result by appending the header of the section where the link appears.

I ended up creating those two function in my Emacs config file:

  (defun org-ql-open-link-in-agenda ()
    "Call `org-ql-open-link' on `org-agenda-files'."
    (interactive)
    (org-ql-open-link (org-agenda-files)))

  (defun org-ql-open-link-in-org-directory ()
    "Call `org-ql-open-link' on files in `org-directory'."
    (interactive)
    (org-ql-open-link (org-ql-search-directories-files)))

One does search across all Org files that appears in the agenda file, the other one search within all Org files of a directory. If you want to use org-ql-open-link-in-org-directory, you simply have to put the following variable to true like this:

  (setq org-ql-search-directories-files-recursive t)

Finally, create a new keybinding that suite you to use those new functions as often as you need.

I just submitted a PR to try to add those directly in org-ql