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.
This commit is contained in:
parent
8f4fa01304
commit
318f7c8f44
|
@ -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"))))))
|
||||
|
|
Loading…
Reference in New Issue