diff options
| author | Juri Linkov | 2025-06-25 19:57:05 +0300 |
|---|---|---|
| committer | Juri Linkov | 2025-06-25 19:57:05 +0300 |
| commit | f3c755129f7d77bd6e18f5005f3c4034c170ea25 (patch) | |
| tree | 25c92aff1ab0a358b7633ef289a69e8f23949f70 /lisp/progmodes/python.el | |
| parent | 789a6b969345d6f9e0c8604bff8618d20a6cf536 (diff) | |
| download | emacs-f3c755129f7d77bd6e18f5005f3c4034c170ea25.tar.gz emacs-f3c755129f7d77bd6e18f5005f3c4034c170ea25.zip | |
Improve treesit settings for python-ts-mode (bug#73404).
* lisp/progmodes/python.el (python--thing-settings):
For the 'sexp' thing use all nodes except top-level
grouping nodes, comments and parens. Add the 'list' thing.
(python-ts-mode): Use setq-local for treesit-thing-settings.
Modify 'forward-sexp-function' and 'treesit-sexp-thing'
after calling 'treesit-major-mode-setup'.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 3966b387998..f4f0518dbfd 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -6123,13 +6123,34 @@ tree-sitter." | |||
| 6123 | (defvar python--thing-settings | 6123 | (defvar python--thing-settings |
| 6124 | `((python | 6124 | `((python |
| 6125 | (defun ,(rx (or "function" "class") "_definition")) | 6125 | (defun ,(rx (or "function" "class") "_definition")) |
| 6126 | (sexp ,(rx (or "expression" | 6126 | (sexp (not (or (and named |
| 6127 | "string" | 6127 | ,(rx bos (or "module" |
| 6128 | "call" | 6128 | "block" |
| 6129 | "operator" | 6129 | "comment") |
| 6130 | "identifier" | 6130 | eos)) |
| 6131 | "integer" | 6131 | (and anonymous |
| 6132 | "float"))) | 6132 | ,(rx bos (or "(" ")" "[" "]" "{" "}" ",") |
| 6133 | eos))))) | ||
| 6134 | (list ,(rx bos (or "parameters" | ||
| 6135 | "type_parameter" | ||
| 6136 | "parenthesized_list_splat" | ||
| 6137 | "argument_list" | ||
| 6138 | "_list_pattern" | ||
| 6139 | "_tuple_pattern" | ||
| 6140 | "dict_pattern" | ||
| 6141 | "tuple_pattern" | ||
| 6142 | "list_pattern" | ||
| 6143 | "list" | ||
| 6144 | "set" | ||
| 6145 | "tuple" | ||
| 6146 | "dictionary" | ||
| 6147 | "list_comprehension" | ||
| 6148 | "dictionary_comprehension" | ||
| 6149 | "set_comprehension" | ||
| 6150 | "generator_expression" | ||
| 6151 | "parenthesized_expression" | ||
| 6152 | "interpolation") | ||
| 6153 | eos)) | ||
| 6133 | (sentence ,(rx (or "statement" | 6154 | (sentence ,(rx (or "statement" |
| 6134 | "clause"))) | 6155 | "clause"))) |
| 6135 | (text ,(rx (or "string" "comment"))))) | 6156 | (text ,(rx (or "string" "comment"))))) |
| @@ -7355,8 +7376,11 @@ implementations: `python-mode' and `python-ts-mode'." | |||
| 7355 | (setq-local treesit-defun-name-function | 7376 | (setq-local treesit-defun-name-function |
| 7356 | #'python--treesit-defun-name) | 7377 | #'python--treesit-defun-name) |
| 7357 | 7378 | ||
| 7358 | (setq treesit-thing-settings python--thing-settings) | 7379 | (setq-local treesit-thing-settings python--thing-settings) |
| 7359 | (treesit-major-mode-setup) | 7380 | (treesit-major-mode-setup) |
| 7381 | ;; Enable the `sexp' navigation by default | ||
| 7382 | (setq-local forward-sexp-function #'treesit-forward-sexp | ||
| 7383 | treesit-sexp-thing 'sexp) | ||
| 7360 | 7384 | ||
| 7361 | (setq-local syntax-propertize-function #'python--treesit-syntax-propertize) | 7385 | (setq-local syntax-propertize-function #'python--treesit-syntax-propertize) |
| 7362 | 7386 | ||