From 281d0de091106d2702b5a7d01f025015c5c44688 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 8 Apr 2025 20:43:41 +0300 Subject: [PATCH] * lisp/treesit.el (treesit--after-change): New function. (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 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index e1eaf8803f0..851c7b3e3da 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -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))) -- 2.39.5