[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter b49250ada9 2/8: Use treesit-fontify-with-override in
From: |
Yuan Fu |
Subject: |
feature/tree-sitter b49250ada9 2/8: Use treesit-fontify-with-override in tree-sitter functions |
Date: |
Tue, 1 Nov 2022 16:28:16 -0400 (EDT) |
branch: feature/tree-sitter
commit b49250ada978c7b21cb93177c874c81a27fa4fec
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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 2801a729eb..e50bc9017c 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 0b10058eeb..916b098aef 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
- feature/tree-sitter updated (9fab83ed7a -> 50e33639fe), Yuan Fu, 2022/11/01
- feature/tree-sitter b49250ada9 2/8: Use treesit-fontify-with-override in tree-sitter functions,
Yuan Fu <=
- feature/tree-sitter a3651d3237 4/8: Query on the root node in tree-sitter font-lock, Yuan Fu, 2022/11/01
- feature/tree-sitter 6d5b34d9de 6/8: ; Tree-sitter font-lock debugging: print node type not language, Yuan Fu, 2022/11/01
- feature/tree-sitter ccd2509ed3 7/8: Don't print buffer when printing tree-sitter node and parser, Yuan Fu, 2022/11/01
- feature/tree-sitter f6e92035a7 5/8: Allow user to add/remove tree-sitter font-lock features, Yuan Fu, 2022/11/01
- feature/tree-sitter eeeae5e9ee 1/8: Add an argument OVERRIDE to tree-sitter font-lock functions, Yuan Fu, 2022/11/01
- feature/tree-sitter 50e33639fe 8/8: Fix string fontification for tree-sitter python-mode, Yuan Fu, 2022/11/01
- feature/tree-sitter 4ef50ccd3f 3/8: ; Explain the BEG and END argument in treesit-query-capture better, Yuan Fu, 2022/11/01