diff options
author | Yuan Fu <casouri@gmail.com> | 2022-12-04 00:22:28 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2022-12-04 20:03:28 -0800 |
commit | ec00d292ec02f34a0d879767c6737fadbe24ce20 (patch) | |
tree | 1d7ddbf47b81fbfab3f846f7f230e3960653e148 /lisp/treesit.el | |
parent | 4bcdb1cc65bf779b6479f99a7aa767ab83b3bae1 (diff) | |
download | emacs-ec00d292ec02f34a0d879767c6737fadbe24ce20.tar.gz emacs-ec00d292ec02f34a0d879767c6737fadbe24ce20.tar.bz2 emacs-ec00d292ec02f34a0d879767c6737fadbe24ce20.zip |
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.
Diffstat (limited to 'lisp/treesit.el')
-rw-r--r-- | lisp/treesit.el | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/lisp/treesit.el b/lisp/treesit.el index f3c03daf7e0..eee6eee0c7f 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -774,25 +774,35 @@ signals the `treesit-font-lock-error' error if that happens." ((memq feature remove-list) nil) (t current-value)))))) -(defun treesit-fontify-with-override (start end face override) +(defun treesit-fontify-with-override + (start end face override &optional bound-start bound-end) "Apply FACE to the region between START and END. OVERRIDE can be nil, t, `append', `prepend', or `keep'. -See `treesit-font-lock-rules' for their semantic." - (pcase override - ('nil (unless (text-property-not-all - start end 'face nil) - (put-text-property start end 'face face))) - ('t (put-text-property start end 'face face)) - ('append (font-lock-append-text-property +See `treesit-font-lock-rules' for their semantic. + +If BOUND-START and BOUND-END are non-nil, only fontify the region +in between them." + (when (or (null bound-start) (null bound-end) + (and bound-start bound-end + (<= bound-start end) + (>= bound-end start))) + (when (and bound-start bound-end) + (setq start (max bound-start start) + end (min bound-end end))) + (pcase override + ('nil (unless (text-property-not-all start end 'face nil) + (put-text-property start end 'face face))) + ('t (put-text-property start end 'face face)) + ('append (font-lock-append-text-property + start end 'face face)) + ('prepend (font-lock-prepend-text-property + start end 'face face)) + ('keep (font-lock-fillin-text-property start end 'face face)) - ('prepend (font-lock-prepend-text-property - start end 'face face)) - ('keep (font-lock-fillin-text-property - start end 'face face)) - (_ (signal 'treesit-font-lock-error - (list - "Unrecognized value of :override option" - override))))) + (_ (signal 'treesit-font-lock-error + (list + "Unrecognized value of :override option" + override)))))) (defun treesit--set-nonsticky (start end sym &optional remove) "Set `rear-nonsticky' property between START and END. |