{"id":3938,"date":"2023-12-06T21:15:45","date_gmt":"2023-12-07T02:15:45","guid":{"rendered":"https:\/\/fgiasson.com\/blog\/?p=3938"},"modified":"2023-12-06T21:16:56","modified_gmt":"2023-12-07T02:16:56","slug":"searching-any-web-link-within-a-org-library-using-org-ql","status":"publish","type":"post","link":"https:\/\/fgiasson.com\/blog\/index.php\/2023\/12\/06\/searching-any-web-link-within-a-org-library-using-org-ql\/","title":{"rendered":"Searching any Web link within a Org library using org-ql"},"content":{"rendered":"\n<p><span>Jon Snader of <a href=\"https:\/\/irreal.org\/blog\/\">Irreal<\/a> recently made a few blog post about using Emacs as &#8220;bookmark launcher&#8221;. You can read them <a href=\"https:\/\/irreal.org\/blog\/?p=11819\">here<\/a> and <a href=\"https:\/\/irreal.org\/blog\/?p=11812\">here<\/a>. Those methods were working well, but I was missing something.<\/span><\/p>\n<p>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. &nbsp;In that process, I do add a lot of reference to different websites in several different Org files.<\/p>\n<p>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.<\/p>\n<p>But, for some reason, I took the opportunity to take 15 minutes to learn about <code>org-ql<\/code> today. While looking at its codebase, I quickly noticed two functions: <code>org-ql-open-link<\/code> which uses Vertico to search for links within the current Org buffer. A few minutes later I noticed the <code>org-ql-find-in-agenda<\/code> which find anything within all the files in the agenda file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">org-ql-open-link-in-agenda<\/h2>\n\n\n\n<p>Within a few minutes, I merged those two functions to create a new <code>org-ql-open-link-in-agenda<\/code> 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 <code>org-ql-open-link<\/code> does put some context in the search result by appending the header of the section where the link appears.<\/p>\n<p>I ended up creating those two function in my Emacs config file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>  (defun org-ql-open-link-in-agenda ()\n    &quot;Call `org-ql-open-link&#39; on `org-agenda-files&#39;.&quot;\n    (interactive)\n    (org-ql-open-link (org-agenda-files)))\n\n  (defun org-ql-open-link-in-org-directory ()\n    &quot;Call `org-ql-open-link&#39; on files in `org-directory&#39;.&quot;\n    (interactive)\n    (org-ql-open-link (org-ql-search-directories-files)))<\/code><\/pre><\/div>\n\n\n\n<p>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 <code>org-ql-open-link-in-org-directory<\/code>, you simply have to put the following variable to <code>true<\/code> like this:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-plain\"><code>  (setq org-ql-search-directories-files-recursive t)<\/code><\/pre><\/div>\n\n\n\n<p>Finally, create a new keybinding that suite you to use those new functions as often as you need.<\/p>\n<p>I just submitted <a href=\"https:\/\/github.com\/alphapapa\/org-ql\/pull\/384\">a PR<\/a> to try to add those directly in <code>org-ql<\/code>.\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Jon Snader of Irreal recently made a few blog post about using Emacs as &#8220;bookmark launcher&#8221;. 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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[279],"tags":[325],"class_list":["post-3938","post","type-post","status-publish","format-standard","hentry","category-emacs","tag-emacs-orgmode"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=3938"}],"version-history":[{"count":6,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3938\/revisions"}],"predecessor-version":[{"id":3944,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/3938\/revisions\/3944"}],"wp:attachment":[{"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=3938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=3938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fgiasson.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=3938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}