]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/treesit.el (treesit--after-change): New function.
authorJuri Linkov <juri@linkov.net>
Tue, 8 Apr 2025 17:43:41 +0000 (20:43 +0300)
committerEshel Yaron <me@eshelyaron.com>
Tue, 8 Apr 2025 19:43:13 +0000 (21:43 +0200)
(treesit-major-mode-setup): Set 'outline-minor-mode-hook'
to add 'treesit--after-change' with 'treesit-update-ranges'
to 'after-change-functions' (bug#77256).

(cherry picked from commit bec2de20469db0767d2bd7f60f0d4dfb20269614)

lisp/treesit.el

index e1eaf8803f0dafc29f59ef62f7fe9acbdcd2cba3..851c7b3e3da26a1787441264a29c47f4e1cbf4b1 100644 (file)
@@ -4061,6 +4061,10 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
 
     level))
 
+(defun treesit--after-change (beg end _len)
+  "Force updating the ranges after each text change."
+  (treesit-update-ranges beg end))
+
 ;;; Hideshow mode
 
 (defun treesit-hs-block-end ()
@@ -4355,7 +4359,16 @@ before calling this function."
       (setq treesit-outline-predicate
             #'treesit-outline-predicate--from-imenu))
     (setq-local outline-search-function #'treesit-outline-search
-                outline-level #'treesit-outline-level))
+                outline-level #'treesit-outline-level)
+    (add-hook 'outline-minor-mode-hook
+              (lambda ()
+                (if (bound-and-true-p outline-minor-mode)
+                    (add-hook 'after-change-functions
+                              #'treesit--after-change
+                              0 t)
+                  (remove-hook 'after-change-functions
+                               #'treesit--after-change t)))
+              nil t))
 
   ;; Remove existing local parsers.
   (dolist (ov (overlays-in (point-min) (point-max)))