diff options
| author | Yuan Fu | 2023-01-07 18:38:24 -0800 |
|---|---|---|
| committer | Yuan Fu | 2023-01-07 18:44:17 -0800 |
| commit | 800e15e3be0569efdaa5e42c82937b1c87b7ec58 (patch) | |
| tree | 5310ec955ab21a1a246558e3c77c328feceadbbb /lisp/progmodes/python.el | |
| parent | 38b63f4c3ce55f998f00ba9a9a48d6f1b4533f7d (diff) | |
| download | emacs-800e15e3be0569efdaa5e42c82937b1c87b7ec58.tar.gz 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/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 20 |
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." | |||
| 1072 | (treesit-fontify-with-override | 1072 | (treesit-fontify-with-override |
| 1073 | string-beg string-end face override start end))) | 1073 | string-beg string-end face override start end))) |
| 1074 | 1074 | ||
| 1075 | (defun python--treesit-fontify-string-interpolation | ||
| 1076 | (node _ start end &rest _) | ||
| 1077 | "Fontify string interpolation. | ||
| 1078 | NODE is the string node. Do not fontify the initial f for | ||
| 1079 | f-strings. START and END mark the region to be | ||
| 1080 | fontified." | ||
| 1081 | ;; This is kind of a hack, it basically removes the face applied by | ||
| 1082 | ;; the string feature, so that following features can apply their | ||
| 1083 | ;; face. | ||
| 1084 | (let ((n-start (treesit-node-start node)) | ||
| 1085 | (n-end (treesit-node-end node))) | ||
| 1086 | (remove-text-properties | ||
| 1087 | (max start n-start) (min end n-end) '(face)))) | ||
| 1088 | |||
| 1075 | (defvar python--treesit-settings | 1089 | (defvar python--treesit-settings |
| 1076 | (treesit-font-lock-rules | 1090 | (treesit-font-lock-rules |
| 1077 | :feature 'comment | 1091 | :feature 'comment |
| @@ -1082,10 +1096,12 @@ fontified." | |||
| 1082 | :language 'python | 1096 | :language 'python |
| 1083 | '((string) @python--treesit-fontify-string) | 1097 | '((string) @python--treesit-fontify-string) |
| 1084 | 1098 | ||
| 1099 | ;; HACK: This feature must come after the string feature and before | ||
| 1100 | ;; other features. Maybe we should make string-interpolation an | ||
| 1101 | ;; option rather than a feature. | ||
| 1085 | :feature 'string-interpolation | 1102 | :feature 'string-interpolation |
| 1086 | :language 'python | 1103 | :language 'python |
| 1087 | :override t | 1104 | '((interpolation) @python--treesit-fontify-string-interpolation) |
| 1088 | '((interpolation (identifier) @font-lock-variable-name-face)) | ||
| 1089 | 1105 | ||
| 1090 | :feature 'definition | 1106 | :feature 'definition |
| 1091 | :language 'python | 1107 | :language 'python |