aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorYuan Fu2022-11-19 16:09:08 -0800
committerYuan Fu2022-11-19 16:09:08 -0800
commit00df4566af9dff0a27fd6da566ef1e53268a6d47 (patch)
treef6786c292777858131ed7dd60cee17c474e722b3 /lisp/progmodes/python.el
parent655957087c8654577e7c59004f16be7abcc2c46c (diff)
downloademacs-00df4566af9dff0a27fd6da566ef1e53268a6d47.tar.gz
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.el49
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): "
6482(defvar prettify-symbols-alist) 6482(defvar prettify-symbols-alist)
6483 6483
6484;;;###autoload 6484;;;###autoload
6485(define-derived-mode python-mode prog-mode "Python" 6485(define-derived-mode python-base-mode prog-mode "Python"
6486 "Major mode for editing Python files. 6486 "Generic major mode for editing Python files.
6487 6487
6488\\{python-mode-map}" 6488This is a generic major mode intended to be inherited by a
6489concrete implementations. Currently there two concrete
6490implementations: `python-mode' and `python-ts-mode'."
6489 (setq-local tab-width 8) 6491 (setq-local tab-width 8)
6490 (setq-local indent-tabs-mode nil) 6492 (setq-local indent-tabs-mode nil)
6491 6493
@@ -6569,11 +6571,30 @@ Add import for undefined name `%s' (empty to skip): "
6569 (when python-indent-guess-indent-offset 6571 (when python-indent-guess-indent-offset
6570 (python-indent-guess-indent-offset)) 6572 (python-indent-guess-indent-offset))
6571 6573
6572 (add-hook 'flymake-diagnostic-functions #'python-flymake nil t) 6574 (add-hook 'flymake-diagnostic-functions #'python-flymake nil t))
6575
6576;;;###autoload
6577(define-derived-mode python-mode python-base-mode "Python"
6578 "Major mode for editing Python files.
6573 6579
6574 (cond 6580\\{python-mode-map}"
6575 ;; Tree-sitter. 6581 (setq-local font-lock-defaults
6576 ((treesit-ready-p 'python-mode 'python) 6582 `(,python-font-lock-keywords
6583 nil nil nil nil
6584 (font-lock-syntactic-face-function
6585 . python-font-lock-syntactic-face-function)))
6586 (setq-local syntax-propertize-function
6587 python-syntax-propertize-function)
6588 (setq-local imenu-create-index-function
6589 #'python-imenu-create-index)
6590 (add-hook 'which-func-functions #'python-info-current-defun nil t))
6591
6592;;;###autoload
6593(define-derived-mode python-ts-mode python-base-mode "Python"
6594 "Major mode for editing Python files, using tree-sitter library.
6595
6596\\{python-mode-map}"
6597 (when (treesit-ready-p 'python-mode 'python)
6577 (treesit-parser-create 'python) 6598 (treesit-parser-create 'python)
6578 (setq-local treesit-font-lock-feature-list 6599 (setq-local treesit-font-lock-feature-list
6579 '(( comment string function-name class-name) 6600 '(( comment string function-name class-name)
@@ -6587,19 +6608,7 @@ Add import for undefined name `%s' (empty to skip): "
6587 (setq-local beginning-of-defun-function 6608 (setq-local beginning-of-defun-function
6588 #'python-treesit-beginning-of-defun) 6609 #'python-treesit-beginning-of-defun)
6589 (setq-local end-of-defun-function #'python-treesit-end-of-defun) 6610 (setq-local end-of-defun-function #'python-treesit-end-of-defun)
6590 (treesit-major-mode-setup)) 6611 (treesit-major-mode-setup)))
6591 ;; Elisp.
6592 (t
6593 (setq-local font-lock-defaults
6594 `(,python-font-lock-keywords
6595 nil nil nil nil
6596 (font-lock-syntactic-face-function
6597 . python-font-lock-syntactic-face-function)))
6598 (setq-local syntax-propertize-function
6599 python-syntax-propertize-function)
6600 (setq-local imenu-create-index-function
6601 #'python-imenu-create-index)
6602 (add-hook 'which-func-functions #'python-info-current-defun nil t))))
6603 6612
6604;;; Completion predicates for M-x 6613;;; Completion predicates for M-x
6605;; Commands that only make sense when editing Python code 6614;; Commands that only make sense when editing Python code