From b49250ada978c7b21cb93177c874c81a27fa4fec Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Mon, 31 Oct 2022 15:08:17 -0700 Subject: [PATCH] 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. --- lisp/progmodes/js.el | 17 +++++++++++------ lisp/progmodes/python.el | 7 ++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index 2801a729ebd..e50bc9017ca 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -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))))) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 0b10058eebe..916b098aefa 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -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 -- 2.39.5