diff options
| author | Yuan Fu | 2022-10-25 13:54:12 -0700 |
|---|---|---|
| committer | Yuan Fu | 2022-10-25 14:07:47 -0700 |
| commit | 7c5d4348330b206aff1f8e5bc4fd241d6a6dc0b5 (patch) | |
| tree | 8e945b0380e34d86d3206f44980e5bf80f0b298c /lisp/progmodes/python.el | |
| parent | 06b5ec4bbde119d14d866fc3713a4ed390d531f2 (diff) | |
| download | emacs-7c5d4348330b206aff1f8e5bc4fd241d6a6dc0b5.tar.gz emacs-7c5d4348330b206aff1f8e5bc4fd241d6a6dc0b5.zip | |
New tree-sitter toggle scheme
This version: central variable, everything controlled by
treesit-settings. Major mode sets up tree-sitter/non-tree-sitter
in a conditional branch, based on the setting.
* lisp/treesit.el (treesit-settings): New option.
(treesit-defun-type-regexp): Change docstring.
(treesit-mode-supported)
(treesit-required-languages)
(treesit--local-variable-backup): Remove variables.
(treesit--backup-local-variable)
(treesit-mode)
(global-treesit-mode--turn-on)
(global-treesit-mode): Remove functions.
(treesit--setting-for-mode): New function.
(treesit-ready-p): New argument MODE, changed REPORT to QUIET, and
LANGUAGEs to LANGUAGE (now it can be a single symbol or a list of
them).
(treesit-major-mode-setup): New function. Mostly comes from
treesit-mode.
* test/src/treesit-tests.el (treesit-misc): New test.
* lisp/progmodes/python.el (python-mode): Move some setup code into
the conditional branch at the end.
* lisp/progmodes/js.el (js-json-mode)
(js-mode): Move some setup code into the conditional branch at the
end.
* lisp/progmodes/ts-mode.el: Move tree-sitter setup into the
conditional branch.
Diffstat (limited to 'lisp/progmodes/python.el')
| -rw-r--r-- | lisp/progmodes/python.el | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 4ac5f2e3b0a..2c0c35174c2 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el | |||
| @@ -6391,15 +6391,6 @@ Add import for undefined name `%s' (empty to skip): " | |||
| 6391 | 6391 | ||
| 6392 | (setq-local forward-sexp-function python-forward-sexp-function) | 6392 | (setq-local forward-sexp-function python-forward-sexp-function) |
| 6393 | 6393 | ||
| 6394 | (setq-local font-lock-defaults | ||
| 6395 | `(,python-font-lock-keywords | ||
| 6396 | nil nil nil nil | ||
| 6397 | (font-lock-syntactic-face-function | ||
| 6398 | . python-font-lock-syntactic-face-function))) | ||
| 6399 | |||
| 6400 | (setq-local syntax-propertize-function | ||
| 6401 | python-syntax-propertize-function) | ||
| 6402 | |||
| 6403 | (setq-local indent-line-function #'python-indent-line-function) | 6394 | (setq-local indent-line-function #'python-indent-line-function) |
| 6404 | (setq-local indent-region-function #'python-indent-region) | 6395 | (setq-local indent-region-function #'python-indent-region) |
| 6405 | ;; Because indentation is not redundant, we cannot safely reindent code. | 6396 | ;; Because indentation is not redundant, we cannot safely reindent code. |
| @@ -6424,14 +6415,9 @@ Add import for undefined name `%s' (empty to skip): " | |||
| 6424 | (add-hook 'post-self-insert-hook | 6415 | (add-hook 'post-self-insert-hook |
| 6425 | #'python-indent-post-self-insert-function 'append 'local) | 6416 | #'python-indent-post-self-insert-function 'append 'local) |
| 6426 | 6417 | ||
| 6427 | (setq-local imenu-create-index-function | ||
| 6428 | #'python-imenu-create-index) | ||
| 6429 | |||
| 6430 | (setq-local add-log-current-defun-function | 6418 | (setq-local add-log-current-defun-function |
| 6431 | #'python-info-current-defun) | 6419 | #'python-info-current-defun) |
| 6432 | 6420 | ||
| 6433 | (add-hook 'which-func-functions #'python-info-current-defun nil t) | ||
| 6434 | |||
| 6435 | (setq-local skeleton-further-elements | 6421 | (setq-local skeleton-further-elements |
| 6436 | '((abbrev-mode nil) | 6422 | '((abbrev-mode nil) |
| 6437 | (< '(backward-delete-char-untabify (min python-indent-offset | 6423 | (< '(backward-delete-char-untabify (min python-indent-offset |
| @@ -6479,13 +6465,27 @@ Add import for undefined name `%s' (empty to skip): " | |||
| 6479 | 6465 | ||
| 6480 | (add-hook 'flymake-diagnostic-functions #'python-flymake nil t) | 6466 | (add-hook 'flymake-diagnostic-functions #'python-flymake nil t) |
| 6481 | 6467 | ||
| 6482 | (setq-local treesit-mode-supported t) | 6468 | (cond |
| 6483 | (setq-local treesit-required-languages '(python)) | 6469 | ;; Tree-sitter. |
| 6484 | (setq-local treesit-font-lock-feature-list | 6470 | ((treesit-ready-p 'python-mode 'python) |
| 6485 | '((basic) (moderate) (elaborate))) | 6471 | (setq-local treesit-font-lock-feature-list |
| 6486 | (setq-local treesit-font-lock-settings python--treesit-settings) | 6472 | '((basic) (moderate) (elaborate))) |
| 6487 | (setq-local treesit-imenu-function | 6473 | (setq-local treesit-font-lock-settings python--treesit-settings) |
| 6488 | #'python-imenu-treesit-create-index)) | 6474 | (setq-local imenu-create-index-function |
| 6475 | #'python-imenu-treesit-create-index) | ||
| 6476 | (treesit-major-mode-setup)) | ||
| 6477 | ;; Elisp. | ||
| 6478 | (t | ||
| 6479 | (setq-local font-lock-defaults | ||
| 6480 | `(,python-font-lock-keywords | ||
| 6481 | nil nil nil nil | ||
| 6482 | (font-lock-syntactic-face-function | ||
| 6483 | . python-font-lock-syntactic-face-function))) | ||
| 6484 | (setq-local syntax-propertize-function | ||
| 6485 | python-syntax-propertize-function) | ||
| 6486 | (setq-local imenu-create-index-function | ||
| 6487 | #'python-imenu-create-index) | ||
| 6488 | (add-hook 'which-func-functions #'python-info-current-defun nil t)))) | ||
| 6489 | 6489 | ||
| 6490 | ;;; Completion predicates for M-x | 6490 | ;;; Completion predicates for M-x |
| 6491 | ;; Commands that only make sense when editing Python code | 6491 | ;; Commands that only make sense when editing Python code |