branch: externals/org-transclusion
commit 4355bfff45d3b50280be56351d78b45e145b7aec
Author: Noboru Ota <[email protected]>
Commit: Noboru Ota <[email protected]>
fix: #286: follow up 71fa901 (#287)
---
org-transclusion.el | 38 +++++++++++++++++++++++++++++++-------
test/test-2.0.org | 2 +-
2 files changed, 32 insertions(+), 8 deletions(-)
diff --git a/org-transclusion.el b/org-transclusion.el
index 1a45eed223..359351e040 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -17,7 +17,7 @@
;; Author: Noboru Ota <[email protected]>
;; Created: 10 October 2020
-;; Last modified: 03 January 2026
+;; Last modified: 04 January 2026
;; URL: https://github.com/nobiot/org-transclusion
;; Keywords: org-mode, transclusion, writing
@@ -1104,16 +1104,40 @@ offsets from file beginning, not from cursor position."
(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))))
+ (move-marker
+ (make-marker)
+ (if (org-transclusion-source-point-beginning-of-buffer-p link)
+ 1 (point)))))
(error (user-error
"Org-transclusion: `org-link-open' cannot open link, %s"
(org-element-property :raw-link link))))))))
+(defun org-transclusion-source-point-beginning-of-buffer-p (link)
+ "Return non-nil when point should be at the beginning of the buffer.
+LINK must be Org's link object that `org-link-open' can act on.
+
+This is meant to be used in`org-transclusion-add-source-marker', which
+should return a marker pointing to the beginning of the buffer (bob =
+point 1) when:
+
+ - Link type is file
+ - No search option
+
+This is so that :lines offsets calculate from file start, not from
+wherever cursor happened to be in source buffer. For other cases, leave
+the point where it is. We are assuming that the `org-link-open' moves
+the point in an appropriate location of the link target buffer, even
+though we cannot guarantee that this is the case. We are limiting the
+case for the marker pointing to the bob only to link type is file
+because:
+
+ - Search option is parsed only when the link type is file.
+ - For other file types, expecially ones from third-party packages such
+ as `orgit', we MUST NOT move the point to the beginning of the
+ buffer."
+ (and (string-equal "file" (org-element-property :type link))
+ (not (org-element-property :search-option link))))
+
(defun org-transclusion-add-org-id (link plist)
"Return a list for Org-ID LINK object and PLIST.
Return nil if not found."
diff --git a/test/test-2.0.org b/test/test-2.0.org
index 51a8adb023..eb2a6f1134 100644
--- a/test/test-2.0.org
+++ b/test/test-2.0.org
@@ -80,7 +80,7 @@ ID with "first section" [[id:2022-06-26T152831]]
Below are tesing the new ~org-transclusion-fix-common-misspelling~ function.
- #+transclude: [[file:test.txt][text file]]
+ #+transclude: [[file:test.txt][text file]] :lines 1-2
::number works now
#+transclude: [[file:test.txt::5]] :lines 1-2