diff options
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 916b098aefa..f741688363e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -1017,7 +1017,7 @@ It makes underscores and dots word constituent chars.") | |||
| 1017 | 1017 | ||
| 1018 | (defun python--treesit-fontify-string (_beg _end node override &rest _) | 1018 | (defun python--treesit-fontify-string (_beg _end node override &rest _) |
| 1019 | "Fontify string. | 1019 | "Fontify string. |
| 1020 | NODE is the last quote in the string. Do not fontify the initial | 1020 | NODE is the leading quote in the string. Do not fontify the initial |
| 1021 | f for f-strings. OVERRIDE is the override flag described in | 1021 | f for f-strings. OVERRIDE is the override flag described in |
| 1022 | `treesit-font-lock-rules'." | 1022 | `treesit-font-lock-rules'." |
| 1023 | (let* ((string (treesit-node-parent node)) | 1023 | (let* ((string (treesit-node-parent node)) |
| @@ -1035,6 +1035,12 @@ f for f-strings. OVERRIDE is the override flag described in | |||
| 1035 | (cl-incf string-beg)) | 1035 | (cl-incf string-beg)) |
| 1036 | (treesit-fontify-with-override string-beg string-end face override))) | 1036 | (treesit-fontify-with-override string-beg string-end face override))) |
| 1037 | 1037 | ||
| 1038 | (defun python--treesit-fontify-string-end (_beg _end node &rest _) | ||
| 1039 | "Mark the whole string as to-be-fontified. | ||
| 1040 | NODE is the ending quote of a string." | ||
| 1041 | (let ((string (treesit-node-parent node))) | ||
| 1042 | (setq jit-lock-context-unfontify-pos (treesit-node-start string)))) | ||
| 1043 | |||
| 1038 | (defvar python--treesit-settings | 1044 | (defvar python--treesit-settings |
| 1039 | (treesit-font-lock-rules | 1045 | (treesit-font-lock-rules |
| 1040 | :feature 'comment | 1046 | :feature 'comment |
| @@ -1044,11 +1050,9 @@ f for f-strings. OVERRIDE is the override flag described in | |||
| 1044 | :feature 'string | 1050 | :feature 'string |
| 1045 | :language 'python | 1051 | :language 'python |
| 1046 | :override t | 1052 | :override t |
| 1047 | ;; Capture the last quote node rather than the whole string. The | 1053 | ;; TODO Document on why we do this. |
| 1048 | ;; whole string might not be captured if it's not contained in the | 1054 | '((string "\"" @python--treesit-fontify-string-end :anchor) |
| 1049 | ;; region being fontified. E.g., the user inserts a quote, that | 1055 | (string :anchor "\"" @python--treesit-fontify-string :anchor)) |
| 1050 | ;; single quote is the whole region we are fontifying. | ||
| 1051 | '((string "\"" @python--treesit-fontify-string :anchor)) | ||
| 1052 | 1056 | ||
| 1053 | :feature 'string-interpolation | 1057 | :feature 'string-interpolation |
| 1054 | :language 'python | 1058 | :language 'python |