diff options
author | Yuan Fu <casouri@gmail.com> | 2022-11-19 16:09:08 -0800 |
---|---|---|
committer | Yuan Fu <casouri@gmail.com> | 2022-11-19 16:09:08 -0800 |
commit | 00df4566af9dff0a27fd6da566ef1e53268a6d47 (patch) | |
tree | f6786c292777858131ed7dd60cee17c474e722b3 /lisp/progmodes/python.el | |
parent | 655957087c8654577e7c59004f16be7abcc2c46c (diff) | |
download | emacs-00df4566af9dff0a27fd6da566ef1e53268a6d47.tar.gz emacs-00df4566af9dff0a27fd6da566ef1e53268a6d47.tar.bz2 emacs-00df4566af9dff0a27fd6da566ef1e53268a6d47.zip |
Split python-mode into native and tree-sitter variant
* lisp/progmodes/python.el (python-base-mode): New virtual mode that
contains most of the setup.
(python-mode): Change to inherit from python-base-mode.
(python-ts-mode): New mode that sets up tree-sitter.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r-- | lisp/progmodes/python.el | 49 |
1 files changed, 29 insertions, 20 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index b9b71a57d7d..01a6887bb6e 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -6482,10 +6482,12 @@ Add import for undefined name `%s' (empty to skip): " (defvar prettify-symbols-alist) ;;;###autoload -(define-derived-mode python-mode prog-mode "Python" - "Major mode for editing Python files. +(define-derived-mode python-base-mode prog-mode "Python" + "Generic major mode for editing Python files. -\\{python-mode-map}" +This is a generic major mode intended to be inherited by a +concrete implementations. Currently there two concrete +implementations: `python-mode' and `python-ts-mode'." (setq-local tab-width 8) (setq-local indent-tabs-mode nil) @@ -6569,11 +6571,30 @@ Add import for undefined name `%s' (empty to skip): " (when python-indent-guess-indent-offset (python-indent-guess-indent-offset)) - (add-hook 'flymake-diagnostic-functions #'python-flymake nil t) + (add-hook 'flymake-diagnostic-functions #'python-flymake nil t)) + +;;;###autoload +(define-derived-mode python-mode python-base-mode "Python" + "Major mode for editing Python files. - (cond - ;; Tree-sitter. - ((treesit-ready-p 'python-mode 'python) +\\{python-mode-map}" + (setq-local font-lock-defaults + `(,python-font-lock-keywords + nil nil nil nil + (font-lock-syntactic-face-function + . python-font-lock-syntactic-face-function))) + (setq-local syntax-propertize-function + python-syntax-propertize-function) + (setq-local imenu-create-index-function + #'python-imenu-create-index) + (add-hook 'which-func-functions #'python-info-current-defun nil t)) + +;;;###autoload +(define-derived-mode python-ts-mode python-base-mode "Python" + "Major mode for editing Python files, using tree-sitter library. + +\\{python-mode-map}" + (when (treesit-ready-p 'python-mode 'python) (treesit-parser-create 'python) (setq-local treesit-font-lock-feature-list '(( comment string function-name class-name) @@ -6587,19 +6608,7 @@ Add import for undefined name `%s' (empty to skip): " (setq-local beginning-of-defun-function #'python-treesit-beginning-of-defun) (setq-local end-of-defun-function #'python-treesit-end-of-defun) - (treesit-major-mode-setup)) - ;; Elisp. - (t - (setq-local font-lock-defaults - `(,python-font-lock-keywords - nil nil nil nil - (font-lock-syntactic-face-function - . python-font-lock-syntactic-face-function))) - (setq-local syntax-propertize-function - python-syntax-propertize-function) - (setq-local imenu-create-index-function - #'python-imenu-create-index) - (add-hook 'which-func-functions #'python-info-current-defun nil t)))) + (treesit-major-mode-setup))) ;;; Completion predicates for M-x ;; Commands that only make sense when editing Python code |