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

    fix: fringe cleanup for non-org source buffers
    
    * org-transclusion-indent-mode.el
    (org-transclusion-indent--refresh-source-region): Branch on
    org-indent-mode to handle org and non-org buffers differently. When
    org-indent-mode is active, refresh properties as before. Otherwise, call
    org-transclusion-remove-fringe-from-region to clean up fringes. Add
    forward declaration for org-transclusion-remove-fringe-from-region.
    
    * org-transclusion.el (org-transclusion-remove-fringe-from-region):
    Check if buffer is derived from org-mode. In org buffers, strip fringes
    while preserving org-indent content. In non-org buffers, remove
    line-prefix and wrap-prefix properties entirely since they were added
    solely for fringe display. Uses derived-mode-p to avoid free variable
    warnings.
---
 org-transclusion-indent-mode.el | 25 ++++++++++++++-------
 org-transclusion.el             | 49 ++++++++++++++++++++++++-----------------
 2 files changed, 46 insertions(+), 28 deletions(-)

diff --git a/org-transclusion-indent-mode.el b/org-transclusion-indent-mode.el
index 96393d222f..532439bfd3 100644
--- a/org-transclusion-indent-mode.el
+++ b/org-transclusion-indent-mode.el
@@ -57,6 +57,8 @@ Either nil, t (initialized), or (TIMER ATTEMPT-COUNT).")
 ;; Silence byte-compiler warnings for functions defined in org-transclusion.el
 (declare-function org-transclusion-prefix-has-fringe-p "org-transclusion" 
(prefix))
 (declare-function org-transclusion-add-fringe-to-region "org-transclusion" 
(buffer beg end face))
+(declare-function org-transclusion-remove-fringe-from-region 
"org-transclusion" (buffer beg end))
+
 
 ;; Variable defined by define-minor-mode later in this file
 (defvar org-transclusion-indent-mode)
@@ -211,14 +213,21 @@ by appending them to org-indent's indentation prefixes."
 
 (defun org-transclusion-indent--refresh-source-region (src-buf src-beg src-end)
   "Refresh org-indent properties in source region after transclusion removal.
-SRC-BUF is the source buffer, SRC-BEG and SRC-END are the region bounds."
-  (when (buffer-local-value 'org-indent-mode src-buf)
-    (with-current-buffer src-buf
-      (org-indent-add-properties src-beg src-end)
-      ;; Check if mode should be disabled
-      (when (and (boundp 'org-transclusion-indent-mode)
-                 org-transclusion-indent-mode)
-        (org-transclusion-indent--check-and-disable)))))
+SRC-BUF is the source buffer, SRC-BEG and SRC-END are the region bounds.
+
+For `org-mode' buffers with `org-indent-mode', refreshes indentation 
properties.
+For non-org buffers, removes fringe indicators that were added during
+transclusion."
+  (with-current-buffer src-buf
+    (if (buffer-local-value 'org-indent-mode src-buf)
+        ;; Org buffer with indent-mode: refresh properties
+        (progn
+          (org-indent-add-properties src-beg src-end)
+          (when (and (boundp 'org-transclusion-indent-mode)
+                     org-transclusion-indent-mode)
+            (org-transclusion-indent--check-and-disable)))
+      ;; Non-org buffer or org buffer without indent-mode: just remove fringes
+      (org-transclusion-remove-fringe-from-region src-buf src-beg src-end))))
 
 ;;;; Minor Mode Definition
 
diff --git a/org-transclusion.el b/org-transclusion.el
index 795c7251f2..6a922477d1 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -1333,10 +1333,11 @@ is non-nil."
 Checks both graphical fringe (display property) and
 terminal fringe (face property)."
   (or
-   ;; Graphical: (left-fringe org-transclusion-fringe-bitmap FACE)
+   ;; Graphical: (left-fringe BITMAP FACE)
+   ;; BITMAP can be 'empty-line (source) or 'org-transclusion-fringe-bitmap 
(destination)
    (and (listp prop-value)
         (eq (car prop-value) 'left-fringe)
-        (eq (cadr prop-value) 'org-transclusion-fringe-bitmap)
+        (memq (cadr prop-value) '(empty-line org-transclusion-fringe-bitmap))
         (memq (nth 2 prop-value)
               '(org-transclusion-source-fringe
                 org-transclusion-fringe)))
@@ -1486,28 +1487,36 @@ Returns the cleaned prefix, or nil if prefix was only 
the fringe indicator."
 This restores `line-prefix' and `wrap-prefix' to their state before
 `org-transclusion-add-fringe-to-region' was called.
 
-Removes only the fringe portion while preserving any other prefix
-content, regardless of whether org-indent-mode is active."
+In `org-mode' buffers, removes only the fringe portion while preserving
+org-indent indentation.  In non-org buffers, removes the properties
+entirely since they were added solely for fringe display."
   (with-current-buffer buffer
     (with-silent-modifications
       (save-excursion
         (goto-char beg)
-        (while (< (point) end)
-          (let* ((line-beg (line-beginning-position))
-                 (line-end (min (1+ line-beg) end))
-                 (line-prefix (get-text-property line-beg 'line-prefix))
-                 (wrap-prefix (get-text-property line-beg 'wrap-prefix)))
-
-            ;; Always strip fringes precisely, preserving other content
-            (when line-prefix
-              (org-transclusion--update-line-prefix
-               line-beg line-end 'line-prefix
-               (org-transclusion-remove-fringe-from-prefix line-prefix)))
-            (when wrap-prefix
-              (org-transclusion--update-line-prefix
-               line-beg line-end 'wrap-prefix
-               (org-transclusion-remove-fringe-from-prefix wrap-prefix))))
-          (forward-line 1))))))
+        (let ((is-org-buffer (derived-mode-p 'org-mode)))
+          (while (< (point) end)
+            (let* ((line-beg (line-beginning-position))
+                   (line-end (min (1+ line-beg) end))
+                   (line-prefix (get-text-property line-beg 'line-prefix))
+                   (wrap-prefix (get-text-property line-beg 'wrap-prefix)))
+
+              (if is-org-buffer
+                  ;; Org buffer: strip fringes, preserve org-indent content
+                  (progn
+                    (when line-prefix
+                      (org-transclusion--update-line-prefix
+                       line-beg line-end 'line-prefix
+                       (org-transclusion-remove-fringe-from-prefix 
line-prefix)))
+                    (when wrap-prefix
+                      (org-transclusion--update-line-prefix
+                       line-beg line-end 'wrap-prefix
+                       (org-transclusion-remove-fringe-from-prefix 
wrap-prefix))))
+                ;; Non-org buffer: remove properties entirely
+                (progn
+                  (org-transclusion--update-line-prefix line-beg line-end 
'line-prefix nil)
+                  (org-transclusion--update-line-prefix line-beg line-end 
'wrap-prefix nil))))
+            (forward-line 1)))))))
 
 ;;;; Hook
 (defun org-transclusion-source-overlay-modified (ov after-p _beg _end 
&optional _len)

Reply via email to