[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter a3651d3237 4/8: Query on the root node in tree-sitte
|
From: |
Yuan Fu |
|
Subject: |
feature/tree-sitter a3651d3237 4/8: Query on the root node in tree-sitter font-lock |
|
Date: |
Tue, 1 Nov 2022 16:28:16 -0400 (EDT) |
branch: feature/tree-sitter
commit a3651d3237e91f788211e507d61c2dcf886c185f
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Query on the root node in tree-sitter font-lock
Rather than querying on the smallest node that spans START to END, we
query on the root node between START to END.
* lisp/progmodes/python.el (python--treesit-fontify-string): Accept
the string rather than the quote node.
(python--treesit-settings): Capture the string rather than the quote
node.
* lisp/treesit.el (treesit-font-lock-fontify-region): Query the root
node rather than the smallest node.
---
lisp/treesit.el | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/lisp/treesit.el b/lisp/treesit.el
index 72c8186044..733d721f10 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -635,17 +635,18 @@ If LOUDLY is non-nil, display some debugging information."
(enable (nth 1 setting))
(override (nth 3 setting))
(language (treesit-query-language query)))
- (when-let ((node (treesit-node-on start end language))
+ ;; Why root node rather than (treesit-node-on start end)? If
+ ;; you insert an ending quote into a buffer, jit-lock only wants
+ ;; to fontify that single quote, and (treesit-node-on start end)
+ ;; will give you that quote node. We want to capture the string
+ ;; and apply string face to it, but querying on the quote node
+ ;; will not give us the string node.
+ (when-let ((root (treesit-buffer-root-node language))
;; Only activate if ENABLE flag is t.
(activate (eq t enable)))
(ignore activate)
(let ((captures (treesit-query-capture
- node query
- ;; Specifying the range is important. More
- ;; often than not, NODE will be the root
- ;; node, and if we don't specify the range,
- ;; we are basically querying the whole file.
- start end))
+ root query start end))
(inhibit-point-motion-hooks t))
(with-silent-modifications
(dolist (capture captures)
- 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, 2022/11/01
- feature/tree-sitter a3651d3237 4/8: Query on the root node in tree-sitter font-lock,
Yuan Fu <=
- 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