>>>> But can we do better? I see that 'treesit-major-mode-setup' >>>> adds the notifier >>>> >>>> (treesit-parser-add-notifier >>>> treesit-primary-parser #'treesit--font-lock-mark-ranges-to-fontify) >>>> >>>> to 'after_change_functions'. But why the treesit >>>> 'after_change_functions' notifier is called after the >>>> 'after-change-functions' hook? Can we change their order? >>> >>> Because we parse lazily. And I should’ve called them after-parse functions >>> in the docstring (good thing I named them notifiers, not >>> after-change-functions)—they get called after the parser re-parses, but the >>> parser doesn’t have to re-parse immediately after a buffer change. It only >>> re-parses when some Lisp asks for a node from the parse tree. >>> >>> In practice, that usually happens in pre-redisplay-function where we set >>> ranges for embedded parsers, which causes the primary parser to re-parse >>> and return a root node for querying. As a (intended) side-effect, the >>> notifiers get called and mark relevant regions to be re-fontified. >> >> Would it be possible on the first attempt of Lisp code to access a node >> to detect such a situation that there are some outdated nodes and >> to update their ranges automatically? > > Probably not, since you need to have correct ranges to know > which parser to use to get nodes in the first place.