[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 50e33639fe 8/8: Fix string fontification for tree-si
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 50e33639fe 8/8: Fix string fontification for tree-sitter python-mode |
Date: |
Tue, 1 Nov 2022 16:28:16 -0400 (EDT) |
branch: feature/tree-sitter
commit 50e33639fe190f0a1c47b8e4c0fcc4735cb60909
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
Fix string fontification for tree-sitter python-mode
Now when user inserts a ending quote, the whole string is ganranteed
to be refontified and redisplayed.
* lisp/progmodes/python.el (python--treesit-fontify-string): Change
docstring, now it's called on the leading quote.
(python--treesit-fontify-string-end): New function.
(python--treesit-settings): Capture both leading and ending quote in a
string.
---
lisp/progmodes/python.el | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 916b098aef..f741688363 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1017,7 +1017,7 @@ It makes underscores and dots word constituent chars.")
(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
+NODE is the leading quote in the string. Do not fontify the initial
f for f-strings. OVERRIDE is the override flag described in
`treesit-font-lock-rules'."
(let* ((string (treesit-node-parent node))
@@ -1035,6 +1035,12 @@ f for f-strings. OVERRIDE is the override flag
described in
(cl-incf string-beg))
(treesit-fontify-with-override string-beg string-end face override)))
+(defun python--treesit-fontify-string-end (_beg _end node &rest _)
+ "Mark the whole string as to-be-fontified.
+NODE is the ending quote of a string."
+ (let ((string (treesit-node-parent node)))
+ (setq jit-lock-context-unfontify-pos (treesit-node-start string))))
+
(defvar python--treesit-settings
(treesit-font-lock-rules
:feature 'comment
@@ -1044,11 +1050,9 @@ f for f-strings. OVERRIDE is the override flag
described in
:feature 'string
:language 'python
:override t
- ;; Capture the last quote node rather than the whole string. The
- ;; whole string might not be captured if it's not contained in the
- ;; region being fontified. E.g., the user inserts a quote, that
- ;; single quote is the whole region we are fontifying.
- '((string "\"" @python--treesit-fontify-string :anchor))
+ ;; TODO Document on why we do this.
+ '((string "\"" @python--treesit-fontify-string-end :anchor)
+ (string :anchor "\"" @python--treesit-fontify-string :anchor))
:feature 'string-interpolation
:language 'python
- 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, 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 <=
- feature/tree-sitter 4ef50ccd3f 3/8: ; Explain the BEG and END argument in treesit-query-capture better, Yuan Fu, 2022/11/01