branch: externals/org-transclusion
commit d8ae9e5fe1aafbf61dfd74746f005011c76996ee
Author: gggion <[email protected]>
Commit: gggion <[email protected]>
feat: add org-transclusion-add-fringe-to-region for per-line fringes
Add function to apply fringe indicators to each line in a region while
preserving existing line-prefix and wrap-prefix text properties. This
enables org-indent-mode compatibility by appending fringes to
org-indent's per-line indentation instead of replacing it.
* org-transclusion.el (org-transclusion-add-fringe-to-region): New
function. Iterates through each line in region, retrieves existing
line-prefix and wrap-prefix properties, appends fringe indicator to
each using org-transclusion-append-fringe-to-prefix, and updates
properties. Uses with-silent-modifications to avoid marking buffer
modified. Only processes lines when org-indent-mode is active in
the target buffer.
The function handles edge cases: uses bounp to check if org-indent-mode
is loaded, then checks if it's active in the buffer, then checks if the
buffer uses line-beginning-position for accurate line boundaries, and
limits property application to region end with (min (1+ line-beg) end)
to avoid extending beyond the intended range.
---
org-transclusion.el | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/org-transclusion.el b/org-transclusion.el
index a3f06bd746..7284402165 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -1319,6 +1319,35 @@ Returns concatenated string suitable for `line-prefix'
or `wrap-prefix'."
(concat existing-prefix fringe-indicator)
fringe-indicator)))
+(defun org-transclusion-add-fringe-to-region (buffer beg end face)
+ "Add fringe indicator to each line in BUFFER between BEG and END.
+FACE determines the fringe color.
+This modifies existing `line-prefix' and `wrap-prefix' text properties
+by appending the fringe indicator, preserving org-indent's indentation.
+Only operates when `org-indent-mode' is active in BUFFER."
+ (with-current-buffer buffer
+ (when (and (boundp 'org-indent-mode) ; Is org-indent loaded?
+ org-indent-mode) ; Is it active in THIS buffer?
+ (with-silent-modifications
+ (save-excursion
+ (goto-char beg)
+ (while (< (point) end)
+ (let* ((line-beg (line-beginning-position))
+ (existing-line-prefix (get-text-property line-beg
'line-prefix))
+ (existing-wrap-prefix (get-text-property line-beg
'wrap-prefix)))
+ ;; Append fringe to existing prefixes
+ (when existing-line-prefix
+ (put-text-property line-beg (min (1+ line-beg) end)
+ 'line-prefix
+ (org-transclusion-append-fringe-to-prefix
+ existing-line-prefix face)))
+ (when existing-wrap-prefix
+ (put-text-property line-beg (min (1+ line-beg) end)
+ 'wrap-prefix
+ (org-transclusion-append-fringe-to-prefix
+ existing-wrap-prefix face))))
+ (forward-line 1)))))))
+
(defun org-transclusion-find-source-marker (beg end)
"Return marker that points to source begin point for transclusion.
It works on the transclusion region at point. BEG and END are