>>>>> Unfortunately, I discovered that it causes treesit-node-outdated errors. >>>>> >>>>> This is because overlays are updated by 'pre-redisplay-functions' >>>>> later than outline-minor-mode uses them by 'after-change-functions', >>>>> since 'after-change-functions' runs before 'pre-redisplay-functions'. >>>> >>>> This fixes the problem: >>>> >>>> (defun outline--fix-buttons-after-change (beg end _len) >>>> + (when (fboundp 'treesit-update-ranges) >>>> + (treesit-update-ranges beg end)) >>>> ;; Handle whole lines >>>> (save-excursion (goto-char beg) (setq beg (pos-bol))) >>>> (save-excursion (goto-char end) (setq end (pos-eol))) >>> >>> Using treesit-update-ranges is the right approach. But is there no >>> better place to put it? I assume there should be a function that >>> involves tree-sitter, in front of which you can put this call. >> >> 'treesit-outline-search' has no information about the positions of >> the beginning and end of the range of changed text. Only >> 'after-change-functions' has access to this information. >> >> So what we could do is this, and I've tested that this approach works: >> >> #+begin_src diff >> diff --git a/lisp/treesit.el b/lisp/treesit.el >> index 07861603244..c77b28c4647 100644 >> --- a/lisp/treesit.el >> +++ b/lisp/treesit.el >> @@ -4044,6 +4112,10 @@ treesit-outline-level >> >> 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 () >> @@ -4338,7 +4410,16 @@ treesit-major-mode-setup >> (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))) >> #+end_src > > This seems a bit convoluted to me. What do you think about adding > some hook or generic function to outline-minor-mode? Is this better?