[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
feature/tree-sitter 00df4566af 3/6: Split python-mode into native and tr
From: |
Yuan Fu |
Subject: |
feature/tree-sitter 00df4566af 3/6: Split python-mode into native and tree-sitter variant |
Date: |
Sat, 19 Nov 2022 21:36:24 -0500 (EST) |
branch: feature/tree-sitter
commit 00df4566af9dff0a27fd6da566ef1e53268a6d47
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>
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.
---
lisp/progmodes/python.el | 49 ++++++++++++++++++++++++++++--------------------
1 file changed, 29 insertions(+), 20 deletions(-)
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index b9b71a57d7..01a6887bb6 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
- feature/tree-sitter updated (59eaa30b07 -> ac9bc819bc), Yuan Fu, 2022/11/19
- feature/tree-sitter 655957087c 2/6: Expand css-ts-mode and merge it into css-mode, Yuan Fu, 2022/11/19
- feature/tree-sitter e41af3971d 1/6: Change tree-sitter indent preset 'match' to count on all nodes, Yuan Fu, 2022/11/19
- feature/tree-sitter 00df4566af 3/6: Split python-mode into native and tree-sitter variant,
Yuan Fu <=
- feature/tree-sitter d6362b632e 4/6: Merge function/class-name features in python-mode, Yuan Fu, 2022/11/19
- feature/tree-sitter ac9bc819bc 6/6: Fix tree-sitter comment indentation for C-like languages, Yuan Fu, 2022/11/19
- feature/tree-sitter 7d7e9ef46a 5/6: Separate native and tree-sitter variant of js-mode, Yuan Fu, 2022/11/19