From 8876f0475696638ad09554daf87d98f738ba9afe Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Sat, 16 Mar 2024 17:08:00 +0100 Subject: [PATCH] Harden shortcut to jump to any Org heading from anywhere In the previous implementation, when in some buffer which is not an Org buffer that accidentally contains lines that partially match the regular expression describing an Org heading, errors could occur when the Org refile cache was empty. To address this issue, let's temporarily switch to some Org buffer before generating the list of all Org heading targets. --- site-lisp/db-org.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 0e4ef1d..067742c 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -1044,7 +1044,15 @@ Current Task: %s(replace-regexp-in-string \"%\" \"%%\" (or org-clock-current-tas " ("c" (db/org-clock-goto-first-open-checkbox nil) nil) - ("a" (org-refile '(4)) nil) + ("a" (with-current-buffer + ;; Make sure we are in some Org buffer, as `org-refile-get-location' + ;; might try to parse the current buffer in search for some Org + ;; headings, possibly producing errors along the way. + (->> (org-agenda-files :unrestricted) + cl-first + get-file-buffer) + (org-refile '(4))) + nil) ("s" (db/org-clock-goto-first-open-checkbox t) nil))