1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Use treesit-fontify-with-override in tree-sitter functions

* lisp/progmodes/js.el (js--fontify-template-string)
* lisp/progmodes/python.el (python--treesit-fontify-string): Use
treesit-fontify-with-override.
This commit is contained in:
Yuan Fu 2022-10-31 15:08:17 -07:00
parent eeeae5e9ee
commit b49250ada9
No known key found for this signature in database
GPG key ID: 56E19BC57664A442
2 changed files with 15 additions and 9 deletions

View file

@ -3573,9 +3573,12 @@ This function is intended for use in `after-change-functions'."
@font-lock-constant-face)))
"Tree-sitter font-lock settings.")
(defun js--fontify-template-string (beg end node _override &rest _)
(defun js--fontify-template-string (beg end node override &rest _)
"Fontify template string but not substitution inside it.
BEG, END, NODE refers to the template_string node."
BEG, END, NODE refers to the template_string node.
OVERRIDE is the override flag described in
`treesit-font-lock-rules'."
(ignore end)
;; You would have thought that the children of the string node spans
;; the whole string. No, the children of the template_string only
@ -3585,10 +3588,12 @@ BEG, END, NODE refers to the template_string node."
(let ((child (treesit-node-child node 0)))
(while child
(if (equal (treesit-node-type child) "template_substitution")
(put-text-property beg (treesit-node-start child)
'face 'font-lock-string-face)
(put-text-property beg (treesit-node-end child)
'face 'font-lock-string-face))
(treesit-fontify-with-override
beg (treesit-node-start child)
'font-lock-string-face override)
(treesit-fontify-with-override
beg (treesit-node-end child)
'font-lock-string-face override))
(setq beg (treesit-node-end child)
child (treesit-node-next-sibling child)))))

View file

@ -1015,10 +1015,11 @@ It makes underscores and dots word constituent chars.")
"VMSError" "WindowsError"
))
(defun python--treesit-fontify-string (_beg _end node _override &rest _)
(defun python--treesit-fontify-string (_beg _end node override &rest _)
"Fontify string.
NODE is the last quote in the string. Do not fontify the initial
f for f-strings."
f for f-strings. OVERRIDE is the override flag described in
`treesit-font-lock-rules'."
(let* ((string (treesit-node-parent node))
(string-beg (treesit-node-start string))
(string-end (treesit-node-end string))
@ -1032,7 +1033,7 @@ f for f-strings."
'font-lock-string-face)))
(when (eq (char-after string-beg) ?f)
(cl-incf string-beg))
(put-text-property string-beg string-end 'face face)))
(treesit-fontify-with-override string-beg string-end face override)))
(defvar python--treesit-settings
(treesit-font-lock-rules