branch: externals/org-transclusion
commit f9ef8bb4ce77510bbf6fcd0dcc09005bfad0de30
Author: gggion <[email protected]>
Commit: gggion <[email protected]>
fix: change emacs -nw fringe detection and reapply during editing
* org-transclusion.el (org-transclusion-prefix-has-fringe-p): Scan every
character position in prefix string for face properties when in terminal
display. Terminal fringes are propertized strings like "| " with face
property on each character, not bare face symbols. The previous
implementation only checked property change boundaries, missing face
properties that span the entire string. Now iterates through all
positions checking for org-transclusion-source-fringe and
org-transclusion-fringe face values, but only when display-graphic-p
returns nil to avoid unnecessary work in graphical mode.
* org-transclusion-indent-mode.el
(org-transclusion-indent--reapply-all-fringes): Always re-apply fringes
to all lines in terminal display. In graphical mode, continue using
first-line optimization since org-indent regenerates entire subtrees at
once. In terminal display, org-indent may regenerate individual lines
during typing, so checking only the first line is insufficient. The
performance cost of re-applying to all lines is negligible in terminal
display since there is no bitmap rendering overhead.
---
org-transclusion-indent-mode.el | 34 ++++++++++++++++++++++------------
org-transclusion.el | 20 +++++++++++++-------
2 files changed, 35 insertions(+), 19 deletions(-)
diff --git a/org-transclusion-indent-mode.el b/org-transclusion-indent-mode.el
index 32e6f3c76b..3dc68766a6 100644
--- a/org-transclusion-indent-mode.el
+++ b/org-transclusion-indent-mode.el
@@ -70,7 +70,13 @@ Either nil, t (initialized), or (TIMER ATTEMPT-COUNT).")
(defun org-transclusion-indent--reapply-all-fringes ()
"Re-apply fringe indicators to all transcluded regions in buffer.
This function is called after any change that might have removed
-`line-prefix' or `wrap-prefix' properties."
+`line-prefix' or `wrap-prefix' properties.
+
+In graphical mode, optimizes by checking only the first line of each
+overlay region, since org-indent regenerates entire subtrees at once.
+
+In terminal mode, always re-applies fringes to all lines, since
+org-indent may regenerate individual lines during typing."
(when (buffer-live-p (current-buffer))
(let ((current-tick (buffer-modified-tick))
(overlays (org-transclusion-indent--find-source-overlays)))
@@ -85,17 +91,21 @@ This function is called after any change that might have
removed
(let ((ov-beg (overlay-start ov))
(ov-end (overlay-end ov)))
(when (and ov-beg ov-end)
- ;; Check if fringes are missing by examining first line
- (save-excursion
- (goto-char ov-beg)
- (let* ((line-beg (line-beginning-position))
- (line-prefix (get-text-property line-beg 'line-prefix)))
- ;; If line-prefix exists but has no fringe, re-apply
- (when (and line-prefix
- (not (org-transclusion-prefix-has-fringe-p
line-prefix)))
- (org-transclusion-add-fringe-to-region
- (current-buffer) ov-beg ov-end
- 'org-transclusion-source-fringe)))))))))))
+ (if (display-graphic-p)
+ ;; Graphical mode: optimize by checking only first line
+ (save-excursion
+ (goto-char ov-beg)
+ (let* ((line-beg (line-beginning-position))
+ (line-prefix (get-text-property line-beg
'line-prefix)))
+ (when (and line-prefix
+ (not (org-transclusion-prefix-has-fringe-p
line-prefix)))
+ (org-transclusion-add-fringe-to-region
+ (current-buffer) ov-beg ov-end
+ 'org-transclusion-source-fringe))))
+ ;; Terminal mode: always re-apply to all lines
+ (org-transclusion-add-fringe-to-region
+ (current-buffer) ov-beg ov-end
+ 'org-transclusion-source-fringe)))))))))
(defun org-transclusion-indent--schedule-reapply ()
"Schedule fringe re-application after a short delay.
diff --git a/org-transclusion.el b/org-transclusion.el
index 9eb9a7c06f..795c7251f2 100644
--- a/org-transclusion.el
+++ b/org-transclusion.el
@@ -1374,7 +1374,7 @@ If NEW-VALUE is nil, removes the property entirely."
(defun org-transclusion-prefix-has-fringe-p (prefix)
"Return non-nil if PREFIX string contains a transclusion fringe indicator.
Checks for both graphical fringe (display property) and terminal
-fringe (face property)."
+fringe (face property within the string)."
(when (stringp prefix)
(let ((pos 0))
(catch 'found
@@ -1383,12 +1383,18 @@ fringe (face property)."
(when (org-transclusion--fringe-spec-p
(get-text-property pos 'display prefix))
(throw 'found t)))
- ;; Check face properties (terminal fringe)
- (setq pos 0)
- (while (setq pos (next-single-property-change pos 'face prefix))
- (when (org-transclusion--fringe-spec-p
- (get-text-property pos 'face prefix))
- (throw 'found t)))
+
+ ;; Check face properties within the string (terminal fringe only)
+ ;; Terminal fringes are strings like "| " with face property
+ (unless (display-graphic-p)
+ (setq pos 0)
+ (while (< pos (length prefix))
+ (let ((face (get-text-property pos 'face prefix)))
+ (when (memq face '(org-transclusion-source-fringe
+ org-transclusion-fringe))
+ (throw 'found t)))
+ (setq pos (1+ pos))))
+
nil))))
;;;; Fringe Creation