Use parser notifier to set parser ranges
This is a continuation from an earlier commit where I added
treesit-parser-changed-ranges and friends. Dmitry raised an concern
about the edge case where the parser re-parses multiple times before
treesit--pre-redisplay has a chance to run and process changed ranges.
Instead of making treesit-parser-changed-ranges DTRT and become more
complicated, it's agreed that using parser notifier is a better
solution (and treesit-parser-changed-ranges can probably be removed).
So, I took out the code that does the work from treesit--pre-redisplay
and put them into treesit--font-lock-mark-ranges-to-fontify. This
function will be called on each parser re-parse. And in
treesit--pre-redisplay, to ensure that treesit--f-l-m-r-to-f gets
called, we force the primary parser to re-parse.
I also added a new variable that major modes need to set,
treesit-primary-parser. I also added code that makes Emacs guess the
primary parser if that variable isn't set.
Documentation fot treesit-primary-parser will come later.
For futher reference, the message id for the message that prompted
this change is <
dc94733b-df75-446c-980e-
1c8ea65826cf@gutov.dev>
* lisp/treesit.el (treesit-primary-parser): New variable.
(treesit--font-lock-mark-ranges-to-fontify): New function.
(treesit--guess-primary-parser): New function.
(treesit--pre-redisplay): Extract out.
(treesit--pre-syntax-ppss): Add comments.
(treesit-major-mode-setup): Guess and set treesit-primary-parser; add
treesit--font-lock-mark-ranges-to-fontify as a notifier to the primary
parser.
(cherry picked from commit
760b54de080c238ea9f7b16055e820862d3e8896)