branch: externals/org-transclusion
commit 71fa9013d5848f80fae9f92caaf34b9900d20db8
Author: gggion <[email protected]>
Commit: Noboru Ota <[email protected]>
fix: enforce point-min when :lines transclusion has no search string
Prevent cursor position in source buffer from affecting line-based
transclusion offsets. When a transclusion link has no search option
(::*Heading, ::CUSTOM_ID, etc.), the marker must point to "point-min"
of the source buffer to ensure ":lines" specifications calculate
offsets from file beginning, not from wherever the cursor happened to
be when the source buffer was opened.
The bug manifested as:
- Cursor at line 500 in source buffer
- Transclusion ":lines 100-105"
- Result: lines 600-605 transcluded (500 + 100 offset)
The fix adds a conditional check after 'org-link-open':
(when (not (org-element-property :search-option link))
(goto-char (point-min)))
This guarantees that links like '[[file:path.org]]' without search
options always start at the beginning of the file for line-based
operations, while links with search options like
'[[file:path.org::*Heading]]' continue to use the search result
position as intended.
Fixes #286
---
org-transclusion.el | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/org-transclusion.el b/org-transclusion.el
index 480a53dfab..1a45eed223 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -1081,7 +1081,11 @@ returned by hooks in `org-transclusion-add-functions'."
"Return the marker of transclusion source by opening LINK.
LINK must be Org's link object that `org-link-open' can act on. As long
as `org-link-open' opens a buffer within Emacs, this function should
-return a marker."
+return a marker.
+
+When LINK has no search option (::*Heading, ::CUSTOM_ID, etc.), returns
+marker at `point-min' to ensure line-based transclusions calculate
+offsets from file beginning, not from cursor position."
;; Assume the point now is the transcluding buffer
;; Note 2025-12-18 `org-link-open' does not necessarily obey
;; `display-buffer-alist' and can open the target buffer in the currently
@@ -1100,6 +1104,11 @@ return a marker."
(org-link-open link)
;; In the target buffer temporarily.
(save-excursion
+ ;; When link has no search option, go to
+ ;; point-min so :lines offsets calculate from file start,
+ ;; not from wherever cursor happened to be in source buffer.
+ (when (not (org-element-property :search-option link))
+ (goto-char (point-min)))
(move-marker (make-marker) (point))))
(error (user-error
"Org-transclusion: `org-link-open' cannot open link, %s"