branch: externals/org-transclusion
commit 1947670b6d37ea93e1a24df817e30a40cca648ca
Author: gggion <[email protected]>
Commit: gggion <[email protected]>
fix: get destination buffer fringe bounds using text property search
* org-transclusion-indent-mode.el
(org-transclusion-indent--add-properties-and-fringes): Find actual
transclusion bounds using text-property-search-forward instead of
trusting beg and end arguments from hook. The hook arguments become
stale after org-transclusion-add-payload removes the #+transclude
keyword line. The keyword removal shifts all positions, but the hook is
called with the pre-removal end position, causing fringes to extend
beyond the actual transcluded content. Searching for the
org-transclusion-type text property gives us the actual bounds of the
transclusion that was just created, since
org-transclusion-content-insert sets this property before our hook runs.
---
org-transclusion-indent-mode.el | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/org-transclusion-indent-mode.el b/org-transclusion-indent-mode.el
index 75c08b8428..32e6f3c76b 100644
--- a/org-transclusion-indent-mode.el
+++ b/org-transclusion-indent-mode.el
@@ -171,20 +171,27 @@ Added to `post-command-hook' in `org-mode' buffers with
`org-indent-mode'."
;;;; Destination Buffer Support
-(defun org-transclusion-indent--add-properties-and-fringes (beg end)
+(defun org-transclusion-indent--add-properties-and-fringes (beg __end)
"Ensure org-indent properties and fringe indicators in transcluded region.
-BEG and END are the transcluded region bounds.
+BEG and END are approximate bounds; we find actual bounds from text properties.
When org-indent-mode is active, `org-indent-add-properties' overwrites
the uniform `line-prefix' and `wrap-prefix' properties set by the main
package, removing fringe indicators. This function re-applies fringes
by appending them to org-indent's indentation prefixes."
(when org-indent-mode
- ;; First ensure org-indent properties exist
- (org-indent-add-properties beg end)
- ;; Then re-apply fringe indicators to destination buffer
- (org-transclusion-add-fringe-to-region
- (current-buffer) beg end 'org-transclusion-fringe)))
+ ;; Find actual transclusion bounds using text properties
+ ;; The transclusion that was just added should be at or near BEG
+ (save-excursion
+ (goto-char beg)
+ ;; Search forward for org-transclusion-type property
+ (when-let* ((match (text-property-search-forward 'org-transclusion-type))
+ (actual-beg (prop-match-beginning match))
+ (actual-end (prop-match-end match)))
+ ;; Apply org-indent properties and fringes to actual bounds
+ (org-indent-add-properties actual-beg actual-end)
+ (org-transclusion-add-fringe-to-region
+ (current-buffer) actual-beg actual-end 'org-transclusion-fringe)))))
(defun org-transclusion-indent--refresh-source-region (src-buf src-beg src-end)
"Refresh org-indent properties in source region after transclusion removal.