branch: externals/org-transclusion
commit 7ecc169c618c62d7fed4023331c0f1e81b170d23
Author: Noboru Ota <[email protected]>
Commit: Noboru Ota <[email protected]>

    fix(lines): Wrong indentation when org ID combined with :lines
---
 org-transclusion-src-lines.el | 13 ++++++++++---
 org-transclusion.el           | 13 ++++++++++---
 test/test-2.0.org             | 14 ++++++++++++--
 3 files changed, 32 insertions(+), 8 deletions(-)

diff --git a/org-transclusion-src-lines.el b/org-transclusion-src-lines.el
index 84a7ab3cf2..822d00c67c 100644
--- a/org-transclusion-src-lines.el
+++ b/org-transclusion-src-lines.el
@@ -17,7 +17,7 @@
 
 ;; Author: Noboru Ota <[email protected]>
 ;; Created: 24 May 2021
-;; Last modified: 19 December 2025
+;; Last modified: 20 December 2025
 
 ;;; Commentary:
 ;;  This is an extension to `org-transclusion'.  When active, it adds features
@@ -109,8 +109,15 @@ Return nil if PLIST does not contain \":src\" or 
\":lines\" properties."
         ;; Link contains a search-option ::<string>
         ;; and NOT for an Org file
         (and (org-element-property :search-option link)
-            (not (org-transclusion-org-file-p (org-element-property :path 
link)))))
-    (append '(:tc-type "lines")
+             (not (org-transclusion-org-file-p (org-element-property :path 
link)))))
+    ;; FIXME :lines can be combined with ID links now, but cannot be with file
+    ;; links to org files. The original design for :lines was to be used only
+    ;; for non-Org files. But this design has not been enforced. We should
+    ;; re-consider :lines. The reason why :tc-type "org-lines" is required here
+    ;; is for `org-transclusion-content-format-functions'.
+    (append (if (string-equal "id" (org-element-property :type link))
+                '(:tc-type "org-lines")
+              '(:tc-type "lines"))
             (org-transclusion-content-range-of-lines link plist)))))
 
 (defun org-transclusion-content-range-of-lines (link plist)
diff --git a/org-transclusion.el b/org-transclusion.el
index eb10d572f3..cb7aae7577 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -1265,9 +1265,17 @@ This function is the default for org-transclusion-type 
(TYPE)
 \"org-*\"."
   (when (org-transclusion-type-is-org type)
     (with-temp-buffer
-      (let ((org-inhibit-startup t))
-        (delay-mode-hooks (org-mode))
+      ;; 
https://github.com/nobiot/org-transclusion/pull/282#issuecomment-3676553675
+      ;; Advice by meedstrom:
+
+      ;; First insert content, then enable Org-mode afterwards, so that
+      ;; `org-set-regexps-and-options' can process "#+STARTUP: odd" and other 
things.
+      ;; These let-bindings are safe methods of speeding it up.
+      ;; Notably, very slow "#+STARTUP: indent" ignored thanks to 
`org-inhibit-startup'.
+      (let ((org-agenda-files nil)
+            (org-inhibit-startup t))
         (insert content)
+        (delay-mode-hooks (org-mode))
         ;; Adjust headline levels
         (org-transclusion-content-format-org-headlines
          type content keyword-values)
@@ -1317,7 +1325,6 @@ active."
                (org-map-entries (lambda ()
                                   (dotimes (_ diff) (org-do-promote))))))))))
 
-
 (defun org-transclusion-content-format (_type content keyword-values)
   "Format text CONTENT from source before transcluding.
 Return content modified (or unmodified, if not applicable).
diff --git a/test/test-2.0.org b/test/test-2.0.org
index 6b73df5ab3..ae879a2a31 100644
--- a/test/test-2.0.org
+++ b/test/test-2.0.org
@@ -43,10 +43,17 @@ ID with "first section" [[id:2022-06-26T152831]]
 
    [[id:2022-10-10T173507::*H2]]
 
-#+transclude: [[id:2022-10-10T173507::*H2]]  :lines 1-5
+   #+transclude: [[id:2022-10-10T173507::*H2]]  :lines 1-5
+   #+transclude: [[id:2022-10-10T173507::*H2]]  :lines 1-5
+
+   #+transclude: [[id:2022-10-10T173507::*H2]] :level
+   #+transclude: [[id:2022-10-10T173507::*H2]]
+
+   #+transclude: [[file:paragraph.org::* Other headline]]  :lines 1-5
 
 ** test empty file
-#+transclude: [[file:empty.txt::2][empty text file]]
+
+   #+transclude: [[file:empty.txt::2][empty text file]]
 
 ** test text
 
@@ -57,8 +64,11 @@ ID with "first section" [[id:2022-06-26T152831]]
 
    #+transclude: [[file:test.txt][text file]]
 
+   ::number works now
    #+transclude: [[file:test.txt::3]]  :lines 1-1
 
+   ::/regexp/ does not work as intended because it will open an occur buffer 
and
+   does not move the point in the source buffer.
    #+transclude: [[file:test.txt::/Gab/]]  :lines 1-1
 
    #+transclude [[file:test.txt][text file]]

Reply via email to