* 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'.
This commit is contained in:
Juri Linkov 2025-08-29 19:27:32 +03:00
parent f7188ed77f
commit b8ad7c38ae

View file

@ -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