branch: externals/org-transclusion
commit b2dac111ce0109d5f3043ef857ff0e8eac642f76
Author: gggion <[email protected]>
Commit: gggion <[email protected]>

    fix: preserve indentation in source and transclusion buffers
    
    Modify org-transclusion-content-insert to preserve org-indent-mode's
    per-line indentation in both source and transclusion buffers. Replace
    overlay-based line-prefix/wrap-prefix properties with per-line text
    properties that append fringe indicators to existing indentation.
    
    * org-transclusion.el (org-transclusion-content-insert): Remove
    line-prefix and wrap-prefix from text properties added to transcluded
    content. Remove line-prefix and wrap-prefix from source overlay
    properties. Add modification-hooks property to source overlay with
    org-transclusion-source-overlay-modified. Call
    org-transclusion-add-fringe-to-region for both source buffer and
    transclusion buffer when org-indent-mode has ben loaded AND is active in
    respective buffers.
    
    Previous code set uniform line-prefix/wrap-prefix as overlay properties,
    which overrode org-indent's per-line text properties. This caused
    source buffers to lose visual indentation when transcluded. New code
    appends fringe indicators to existing per-line properties, preserving
    org-indent's indentation while adding transclusion indicators.
    
    Performance: per-line property updates only occur when org-indent-mode
    has ben loaded AND is active in the involved buffers. When
    org-indent-mode is inactive, no per-line iteration happens, avoiding
    performance cost.
---
 org-transclusion.el | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/org-transclusion.el b/org-transclusion.el
index 3e910e5805..091f7df6c2 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -1046,23 +1046,27 @@ based on the following arguments:
           org-transclusion-id ,id
           org-transclusion-type ,type
           org-transclusion-pair ,tc-pair
-          org-transclusion-orig-keyword ,keyword-values
-          ;; TODO Fringe is not supported for terminal
-          line-prefix ,(org-transclusion-propertize-transclusion)
-          wrap-prefix ,(org-transclusion-propertize-transclusion)))
-      ;; Put the transclusion overlay
-      (let ((ov-tc (text-clone-make-overlay beg end)))
-        (overlay-put ov-tc 'evaporate t)
-        (overlay-put ov-tc 'face 'org-transclusion)
-        (overlay-put ov-tc 'priority -60))
+          org-transclusion-orig-keyword ,keyword-values))
       ;; Put to the source overlay
       (overlay-put ov-src 'org-transclusion-by id)
       (overlay-put ov-src 'org-transclusion-buffer tc-buffer)
       (overlay-put ov-src 'evaporate t)
       (overlay-put ov-src 'face 'org-transclusion-source)
-      (overlay-put ov-src 'line-prefix (org-transclusion-propertize-source))
-      (overlay-put ov-src 'wrap-prefix (org-transclusion-propertize-source))
+      (overlay-put ov-src 'modification-hooks
+                   '(org-transclusion-source-overlay-modified))
       (overlay-put ov-src 'priority -60)
+
+      ;; Apply fringe indicators per-line when org-indent-mode is active
+      ;; Check source buffer's org-indent-mode state
+      (when (and (boundp 'org-indent-mode)
+                 (buffer-local-value 'org-indent-mode sbuf))
+        (org-transclusion-add-fringe-to-region
+         sbuf sbeg send 'org-transclusion-source-fringe))
+
+      ;; Check transclusion buffer's org-indent-mode state
+      (when (and (boundp 'org-indent-mode) org-indent-mode)
+        (org-transclusion-add-fringe-to-region
+         (current-buffer) beg end 'org-transclusion-fringe))
       ;; TODO this should not be necessary, but it is at the moment
       ;; live-sync-enclosing-element fails without tc-pair on source overlay
       (overlay-put ov-src 'org-transclusion-pair tc-pair))

Reply via email to