summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorYuan Fu <casouri@gmail.com>2023-01-07 18:38:24 -0800
committerYuan Fu <casouri@gmail.com>2023-01-07 18:44:17 -0800
commit800e15e3be0569efdaa5e42c82937b1c87b7ec58 (patch)
tree5310ec955ab21a1a246558e3c77c328feceadbbb /lisp
parent38b63f4c3ce55f998f00ba9a9a48d6f1b4533f7d (diff)
downloademacs-800e15e3be0569efdaa5e42c82937b1c87b7ec58.tar.gz
emacs-800e15e3be0569efdaa5e42c82937b1c87b7ec58.tar.bz2
emacs-800e15e3be0569efdaa5e42c82937b1c87b7ec58.zip
Fix string-interpolation feature of python-ts-mode (bug#60599)
* lisp/progmodes/python.el: (python--treesit-fontify-string-interpolation): New function. (python--treesit-settings): Use the new function for string-interpolation.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/progmodes/python.el20
1 files changed, 18 insertions, 2 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index c399bbc64f8..e6ded7a0646 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -1072,6 +1072,20 @@ fontified."
(treesit-fontify-with-override
string-beg string-end face override start end)))
+(defun python--treesit-fontify-string-interpolation
+ (node _ start end &rest _)
+ "Fontify string interpolation.
+NODE is the string node. Do not fontify the initial f for
+f-strings. START and END mark the region to be
+fontified."
+ ;; This is kind of a hack, it basically removes the face applied by
+ ;; the string feature, so that following features can apply their
+ ;; face.
+ (let ((n-start (treesit-node-start node))
+ (n-end (treesit-node-end node)))
+ (remove-text-properties
+ (max start n-start) (min end n-end) '(face))))
+
(defvar python--treesit-settings
(treesit-font-lock-rules
:feature 'comment
@@ -1082,10 +1096,12 @@ fontified."
:language 'python
'((string) @python--treesit-fontify-string)
+ ;; HACK: This feature must come after the string feature and before
+ ;; other features. Maybe we should make string-interpolation an
+ ;; option rather than a feature.
:feature 'string-interpolation
:language 'python
- :override t
- '((interpolation (identifier) @font-lock-variable-name-face))
+ '((interpolation) @python--treesit-fontify-string-interpolation)
:feature 'definition
:language 'python