From b8ad7c38aebeb457f81e8298d9be10d9d30f2921 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Fri, 29 Aug 2025 19:27:32 +0300 Subject: [PATCH] * lisp/progmodes/python.el: Use 'treesit-major-mode-remap-alist'. (python-ts-mode): Don't duplicate 'auto-mode-alist' and 'interpreter-mode-alist' settings in Emacs 31 (bug#79180). Add ts-mode mapping to 'treesit-major-mode-remap-alist'. --- lisp/progmodes/python.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 3cd20d6babf..649f47f6e69 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -7424,12 +7424,19 @@ implementations: `python-mode' and `python-ts-mode'." (when python-indent-guess-indent-offset (python-indent-guess-indent-offset)) - (add-to-list 'auto-mode-alist (cons python--auto-mode-alist-regexp 'python-ts-mode)) - (add-to-list 'interpreter-mode-alist '("python[0-9.]*" . python-ts-mode)))) + (unless (boundp 'treesit-major-mode-remap-alist) ; Emacs 31.1 + (add-to-list 'auto-mode-alist (cons python--auto-mode-alist-regexp 'python-ts-mode)) + (add-to-list 'interpreter-mode-alist '("python[0-9.]*" . python-ts-mode))))) (when (fboundp 'derived-mode-add-parents) ; Emacs 30.1 (derived-mode-add-parents 'python-ts-mode '(python-mode))) +;;;###autoload +(when (and (fboundp 'treesit-available-p) (treesit-available-p) + (boundp 'treesit-major-mode-remap-alist)) ; Emacs 31.1 + (add-to-list 'treesit-major-mode-remap-alist + '(python-mode . python-ts-mode))) + ;;; Completion predicates for M-x ;; Commands that only make sense when editing Python code. (dolist (sym '(python-add-import