From 318f7c8f44c5ab61e6f757bdb8fc7dc40aa44c56 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Thu, 1 Apr 2021 17:02:01 +0200 Subject: [PATCH] Fix reference to wrong buffer when creating links to other items When finding the location of an Org mode item to link to, `org-refile-get-location` may return a point even if the target buffer is not the default buffer. Resolving point in the default buffer thus yields a false marker and the inserted link is wrong. To remedy this, also consider the file name returned by `org-refile-get-location` to resolve point in the file buffer for that file. --- site-lisp/db-org.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index 32da47d..75ea152 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -689,13 +689,16 @@ linking to any item." :maxlevel . 9) (nil :maxlevel . 9)) '((nil :maxlevel . 9)))) - (pom (nth 3 (org-refile-get-location nil default-buffer)))) + (target-pointer (org-refile-get-location)) + (pom (nth 3 target-pointer))) (cond ((markerp pom) pom) ((integerp pom) - ;; Convert point to marker to ensure we are always in the correct buffer + ;; Convert point to marker to ensure we are always in the correct + ;; buffer; the second element of `target-pointer' contains the path to + ;; the target file (save-mark-and-excursion - (with-current-buffer default-buffer + (with-current-buffer (find-file-noselect (nth 1 target-pointer)) (goto-char pom) (point-marker)))) (t (user-error "Invalid location"))))))