branch: externals/org-transclusion
commit 476473956241fe3c1dc828ca9294a084066c55a2
Author: Noboru Ota <[email protected]>
Commit: Noboru Ota <[email protected]>
fix: ID links with search option (9.7+)
---
org-transclusion.el | 44 ++++++++++++++++++++++++++------------------
test/test-2.0.org | 35 ++++++++++++++++++++---------------
2 files changed, 46 insertions(+), 33 deletions(-)
diff --git a/org-transclusion.el b/org-transclusion.el
index e7a14b4ef3..bb1beebd85 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 2025
+;; Last modified: 28 September 2025
;; URL: https://github.com/nobiot/org-transclusion
;; Keywords: org-mode, transclusion, writing
@@ -947,17 +947,23 @@ inserted when more than one space is inserted between
symbols."
;;;; Add-at-point functions
(defun org-transclusion-add-target-marker (link)
- (save-selected-window
- ;; Don't ever prompt to create a headline when transcluding.
- ;; t is a less surprising default than nil - fuzzy search.
- (let ((org-link-search-must-match-exact-headline t))
- (condition-case nil
- (progn
- (org-link-open link)
- ;; In the target buffer temporarily
- (move-marker (make-marker) (point)))
- ;; TODO add more link info
- (error (message "Cannot open link"))))))
+ ;; Assume the point now is the transcluding buffer
+ (let ((cur-buf (current-buffer))
+ (cur-marker (move-marker (make-marker) (line-beginning-position))))
+ (save-excursion
+ ;; Don't ever prompt to create a headline when transcluding.
+ ;; t is a less surprising default than nil - fuzzy search.
+ (let ((org-link-search-must-match-exact-headline t))
+ (condition-case nil
+ (progn
+ (org-link-open link)
+ ;; In the target buffer temporarily. If the target and source are
+ ;; the same buffer, do not move the point and return the curent
+ ;; maker.
+ (if (eq cur-buf (current-buffer)) cur-marker
+ (move-marker (make-marker) (point))))
+ ;; TODO add more link info
+ (error (message "Cannot open link")))))))
(defun org-transclusion-add-org-id (link plist)
"Return a list for Org-ID LINK object and PLIST.
@@ -980,8 +986,10 @@ Return nil if not found."
(defun org-transclusion-add-org-file (link plist)
"Return a list for Org file LINK object and PLIST.
Return nil if not found."
- (and-let* ((_ (string= "file" (org-element-property :type link)))
- (_ (org-transclusion-org-file-p (org-element-property :path
link)))
+ (and-let* ((_ (or (string= "file" (org-element-property :type link))
+ (string= "fuzzy" (org-element-property :type link))))
+ (_ (or (org-transclusion-org-file-p (org-element-property :path
link))
+ (string= "fuzzy" (org-element-property :type link))))
;; The target needs to be carefully differentiated between the whole buffer
or
;; element at point.
@@ -1264,10 +1272,10 @@ property controls the filter applied to the
transclusion."
#'org-transclusion-content-filter-org-first-section
nil nil org-element-all-elements nil)))
;; Apply other filters
- (dolist (fn org-transclusion-content-filter-org-functions)
- (let ((obj-returned (funcall fn obj plist)))
- ;; If nil is returned, do not change the org-content (obj)
- (when obj-returned (setq obj obj-returned))))
+ (dolist (fn org-transclusion-content-filter-org-functions)
+ (let ((obj-returned (funcall fn obj plist)))
+ ;; If nil is returned, do not change the org-content (obj)
+ (when obj-returned (setq obj obj-returned))))
obj)
(defun org-transclusion-content-filter-org-expand-links-function (obj plist)
diff --git a/test/test-2.0.org b/test/test-2.0.org
index 4d4af4a6c5..04051e31e3 100644
--- a/test/test-2.0.org
+++ b/test/test-2.0.org
@@ -1,22 +1,26 @@
-This is first content
+#+title: Test file for Org-transclusion
+
+This is the first section before the first headline.
+
* Regression
** notmuch
#+transclude: [[notmuch:id:[email protected]]]
[[notmuch:id:[email protected]]]
-** search option
-#+transclude: [[file:paragraph.org]]
-=> transclude entire buffer
+** file search option
+
+ #+transclude: [[file:paragraph.org]]
+ => transclude entire buffer
-#+transclude: [[file:paragraph.org::Sub heading]]
-=> Sub heading only
+ #+transclude: [[file:paragraph.org::Sub heading][This is a description]]
+ => Sub heading only
-#+transclude: [[file:paragraph.org::non-exisitent]]
-=> Should not transclude anything
+ #+transclude: [[file:paragraph.org::non-exisitent]]
+ => Should not transclude anything
-** make from link -- id
+** make from link -- ID and ID with search option
This is a link to a [[id:2022-05-30T203553][Bertrand Russell]] wikipedia
excerpt
#+transclude: [[id:2022-05-30T203553][Bertrand Russell]]
@@ -83,7 +87,8 @@ t/nil will be dropped after remove-at-point
#+transclude: [[file:paragraph.org::quote][Link to a quote]]
** #Custom ID
-#+transclude: [[file:testpara.org::#custom-id-1][Custom ID]] :level 2
+
+ #+transclude: [[file:testpara.org::#custom-id-1][Custom ID]] :level 2
** *Hadline
#+transclude: [[file:bertrand-russell.org::*Bertrand Russell - Wikipedia]]
:level 2 :disable-auto
@@ -116,16 +121,16 @@ Temporarily set ~org-transclusion-include-first-section~
to nil
** center-block dynamic-block example-block export-block special-block
verse-block
** drawer
-#+begin_example
-(setq org-transclusion-exclude-elements '())
-(setq org-transclusion-exclude-elements '(property-drawer))
-#+end_example
+
+ #+begin_example
+ (setq org-transclusion-exclude-elements '())
+ (setq org-transclusion-exclude-elements '(property-drawer))
+ #+end_example
#+transclude: [[id:2022-05-30T203553][Bertrand Russell]]
** fixed-width
-
** latex-environment
** plain-list