Improve treesit-fontify-with-override

This also fixes fontification problem with c-ts-mode--fontify-defun.

Now treesit-fontify-with-override clips the fontification region for
the user, so no need for (max start node-start) shenanigans anymore.
More importantly it doesn't fontify unless the region between
node-start and node-end intersects with the region between start and
end, which fixes the problem with c-ts-mode--fontify-defun.

* lisp/treesit.el (treesit-fontify-with-override): Add optional
parameter BOUND-START and BOUND-END.  Wrap the function body in a
when-form.
* lisp/progmodes/c-ts-mode.el (c-ts-mode--fontify-declarator)
(c-ts-mode--fontify-variable)
(c-ts-mode--fontify-defun)
(c-ts-fontify-error)
* lisp/progmodes/js.el (js--fontify-template-string)
* lisp/progmodes/python.el (python--treesit-fontify-string): Use the
new signature.
This commit is contained in:
Yuan Fu 2022-12-04 00:22:28 -08:00
parent 4bcdb1cc65
commit ec00d292ec
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
4 changed files with 39 additions and 35 deletions

View file

@ -1069,7 +1069,7 @@ fontified."
(when (eq (char-after string-beg) ?f)
(cl-incf string-beg))
(treesit-fontify-with-override
(max start string-beg) (min end string-end) face override)))
string-beg string-end face override start end)))
(defvar python--treesit-settings
(treesit-font-lock-rules