emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/indent-bars 8d8b0b964b 292/431: Do not test bol but poi


From: ELPA Syncer
Subject: [elpa] externals/indent-bars 8d8b0b964b 292/431: Do not test bol but point to skip scope update, simplify markers
Date: Mon, 16 Sep 2024 12:59:40 -0400 (EDT)

branch: externals/indent-bars
commit 8d8b0b964b47149359b75e834b620ccb6e872a5c
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>

    Do not test bol but point to skip scope update, simplify markers
    
    Scope can change based on position within the same line.  Simplify the
    setting markers.  It may not be necessary to have the begin range be a
    marker.
---
 indent-bars-ts.el | 74 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 38 insertions(+), 36 deletions(-)

diff --git a/indent-bars-ts.el b/indent-bars-ts.el
index 745ca89031..69aaaa9acf 100644
--- a/indent-bars-ts.el
+++ b/indent-bars-ts.el
@@ -222,8 +222,8 @@ mentioned in 
`indent-bars-treesit-ignore-blank-lines-types'."
     :documentation "The clipping window for the current scope.")
   ( start-bars 0 :type integer
     :documentation "The number of bars shown at start of current scope.")
-  ( bol-point -1 :type integer
-    :documentation "Point at line beginning during last scope update.")
+  ( point -1 :type integer
+    :documentation "Point during last scope update.")
   ( tick 0 :type integer
     :documentation "Buffer modification tick at last scope update.")
   ( query nil :type ts-query
@@ -314,40 +314,42 @@ marker movement), refontify the union of old and new 
clipped
 ranges and update.  Note that the updated node range clips to an
 \"extended window\" with 50% padding on either side."
   (setq indent-bars-ts--scope-timer nil)
-  (let ((lbp (line-beginning-position)))
-    (unless (or (not ibtcs)       ; can be called from other buffers!
-               (and (= lbp (ibts/bol-point ibtcs))
-                    (= (buffer-modified-tick) (ibts/tick ibtcs))))
-      (when-let ((node (treesit-node-on
-                       (max (point-min) (1- (point))) (point)
-                       indent-bars-ts--parser))
-                (scope (indent-bars-ts--node-query
-                        node (ibts/query ibtcs) nil 'innermost
-                        indent-bars-treesit-scope-min-lines)))
-       (let* ((old (ibts/range ibtcs))      ;old node range markers
-              (old-clip (ibts/clip-win ibtcs)) ;old clipping window
-              (win (cons (window-start) (window-end)))
-              (new (cons (treesit-node-start scope) (treesit-node-end scope))))
-         (unless (and (equal new old) ; if node is the same and
-                      (>= (car win) (car old-clip)) ; window inside old range:
-                      (<= (cdr win) (cdr old-clip))) ; no update needed
-           (let* ((marg (/ (- (cdr win) (car win)) 2)) ; a bit of space
-                  (clip-wide (cons (max (point-min) (- (car win) marg))
-                                   (min (point-max) (+ (cdr win) marg)))))
-             (setf (ibts/tick ibtcs) (buffer-modified-tick)
-                   (ibts/bol-point ibtcs) lbp
-                   (ibts/start-bars ibtcs)
-                   (save-excursion
-                     (goto-char (car new))
-                     (indent-bars--current-indentation-depth)))
-             (cl-loop for rng in (indent-bars-ts--union old new)
-                      for (beg . end) = (indent-bars-ts--intersection rng 
clip-wide)
-                      do (font-lock-flush beg end))
-             (dolist (fn '(car cdr))
-               (set-marker (funcall fn (ibts/range ibtcs))
-                           (funcall fn new))
-               (set-marker (funcall fn (ibts/clip-win ibtcs))
-                           (funcall fn clip-wide))))))))))
+  (unless (or (not ibtcs)         ; can be called from other buffers!
+             (and (= (point) (ibts/point ibtcs))
+                  (= (buffer-modified-tick) (ibts/tick ibtcs))))
+    (setf (ibts/tick ibtcs) (buffer-modified-tick)
+         (ibts/point ibtcs) (point))
+    (when-let ((node (treesit-node-on
+                     (max (point-min) (1- (point))) (point)
+                     indent-bars-ts--parser))
+              (scope (indent-bars-ts--node-query
+                      node (ibts/query ibtcs) nil 'innermost
+                      indent-bars-treesit-scope-min-lines)))
+      (let* ((old (ibts/range ibtcs))        ;old node range markers
+            (old-clip (ibts/clip-win ibtcs)) ;old clipping window
+            (win (cons (window-start) (window-end)))
+            (new (cons (treesit-node-start scope) (treesit-node-end scope))))
+       (unless (and (= (car new) (car old)) ; if node spans the
+                    (= (cdr new) (cdr old)) ; same positions and the
+                    (>= (car win) (car old-clip)) ; window is inside old range:
+                    (<= (cdr win) (cdr old-clip))) ; no update needed
+         (let* ((marg (/ (- (cdr win) (car win)) 2)) ; add a bit of space
+                (clip-wide (cons (max (point-min) (- (car win) marg))
+                                 (min (point-max) (+ (cdr win) marg)))))
+           (setf (ibts/start-bars ibtcs)
+                 (save-excursion
+                   (goto-char (car new))
+                   (indent-bars--current-indentation-depth)))
+           (cl-loop for rng in (indent-bars-ts--union old new)
+                    for (beg . end) = (indent-bars-ts--intersection rng 
clip-wide)
+                    if (and beg end)
+                    do
+                    (message "Flushing %d lines" (count-lines beg end))
+                    (font-lock-flush beg end))
+           (set-marker (car old) (car new))
+           (set-marker (cdr old) (cdr new))
+           (set-marker (car old-clip) (car clip-wide))
+           (set-marker (cdr old-clip) (cdr clip-wide))))))))
 
 (defun indent-bars-ts--update-scope ()
   "Update treesit scope when possible."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]