diff options
| author | Yuan Fu | 2022-11-24 10:18:14 -0800 |
|---|---|---|
| committer | Yuan Fu | 2022-11-24 13:47:27 -0800 |
| commit | fc9d7b3d047dbf60a07baa7fa92d5db90f562d28 (patch) | |
| tree | 22014243bad061758ee582d0108ec869c202b973 /lisp/progmodes/python.el | |
| parent | 55f6f1c82a35f0589d3dbdd1f32fae7ea9a758d8 (diff) | |
| download | emacs-fc9d7b3d047dbf60a07baa7fa92d5db90f562d28.tar.gz emacs-fc9d7b3d047dbf60a07baa7fa92d5db90f562d28.zip | |
Improve python-ts-mode fontification (bug#59534)
* lisp/progmodes/python.el (python--treesit-operators): Add operators.
(python--treesit-fontify-string): Fontify BOF docstrings.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index f97ae81508a..221e16f8f77 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -988,7 +988,7 @@ It makes underscores and dots word constituent chars.") | |||
| 988 | 988 | ||
| 989 | (defvar python--treesit-operators | 989 | (defvar python--treesit-operators |
| 990 | '("-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "%" "%=" | 990 | '("-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "%" "%=" |
| 991 | "^" "+" "+=" "<" "<<" "<=" "<>" "=" "==" ">" ">=" ">>" "|" "~")) | 991 | "^" "+" "+=" "<" "<<" "<=" "<>" "=" "==" ">" ">=" ">>" "|" "~" "@" "@=")) |
| 992 | 992 | ||
| 993 | (defvar python--treesit-special-attributes | 993 | (defvar python--treesit-special-attributes |
| 994 | '("__annotations__" "__closure__" "__code__" | 994 | '("__annotations__" "__closure__" "__code__" |
| @@ -1033,12 +1033,27 @@ fontified." | |||
| 1033 | (let* ((string-beg (treesit-node-start node)) | 1033 | (let* ((string-beg (treesit-node-start node)) |
| 1034 | (string-end (treesit-node-end node)) | 1034 | (string-end (treesit-node-end node)) |
| 1035 | (maybe-expression (treesit-node-parent node)) | 1035 | (maybe-expression (treesit-node-parent node)) |
| 1036 | (maybe-defun (treesit-node-parent | 1036 | (grandparent (treesit-node-parent |
| 1037 | (treesit-node-parent | 1037 | (treesit-node-parent |
| 1038 | maybe-expression))) | 1038 | maybe-expression))) |
| 1039 | (face (if (and (member (treesit-node-type maybe-defun) | 1039 | (maybe-defun grandparent) |
| 1040 | '("function_definition" | 1040 | (face (if (and (or (member (treesit-node-type maybe-defun) |
| 1041 | "class_definition")) | 1041 | '("function_definition" |
| 1042 | "class_definition")) | ||
| 1043 | ;; If the grandparent is null, meaning the | ||
| 1044 | ;; string is top-level, and the string has | ||
| 1045 | ;; no node or only comment preceding it, | ||
| 1046 | ;; it's a BOF docstring. | ||
| 1047 | (and (null grandparent) | ||
| 1048 | (cl-loop | ||
| 1049 | for prev = (treesit-node-prev-sibling | ||
| 1050 | maybe-expression) | ||
| 1051 | then (treesit-node-prev-sibling prev) | ||
| 1052 | while prev | ||
| 1053 | if (not (equal (treesit-node-type prev) | ||
| 1054 | "comment")) | ||
| 1055 | return nil | ||
| 1056 | finally return t))) | ||
| 1042 | ;; This check filters out this case: | 1057 | ;; This check filters out this case: |
| 1043 | ;; def function(): | 1058 | ;; def function(): |
| 1044 | ;; return "some string" | 1059 | ;; return "some string" |