From bec2de20469db0767d2bd7f60f0d4dfb20269614 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). --- lisp/treesit.el | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lisp/treesit.el b/lisp/treesit.el index 888f067e0cc..8e57a6dae14 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -4068,6 +4068,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 () @@ -4362,7 +4366,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)))