1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

Check if treesit-major-mode-remap-alist is bound in ts-modes autoload forms

* lisp/progmodes/c-ts-mode.el:
* lisp/progmodes/cmake-ts-mode.el:
* lisp/progmodes/csharp-mode.el:
* lisp/progmodes/dockerfile-ts-mode.el:
* lisp/progmodes/elixir-ts-mode.el:
* lisp/progmodes/go-ts-mode.el:
* lisp/progmodes/heex-ts-mode.el:
* lisp/progmodes/java-ts-mode.el:
* lisp/progmodes/js.el:
* lisp/progmodes/json-ts-mode.el:
* lisp/progmodes/lua-ts-mode.el:
* lisp/progmodes/php-ts-mode.el:
* lisp/progmodes/python.el:
* lisp/progmodes/ruby-ts-mode.el:
* lisp/progmodes/rust-ts-mode.el:
* lisp/progmodes/sh-script.el:
* lisp/progmodes/typescript-ts-mode.el:
* lisp/textmodes/css-mode.el:
* lisp/textmodes/markdown-ts-mode.el:
* lisp/textmodes/mhtml-ts-mode.el:
* lisp/textmodes/toml-ts-mode.el:
* lisp/textmodes/yaml-ts-mode.el: In autoload forms replace
'(treesit-available-p)' with (boundp 'treesit-major-mode-remap-alist).
Calling 'treesit-available-p' in loaddefs.el is too early
since the tree-sitter library might not be loaded yet.
Checking if 'treesit-major-mode-remap-alist' is bound is
equivalent to checking if Emacs is compiled with tree-sitter support.
(bug#79622)
This commit is contained in:
Juri Linkov 2025-10-16 09:43:30 +03:00
parent 88c18efb3a
commit 0a4503de3a
22 changed files with 25 additions and 50 deletions

View file

@ -1674,8 +1674,7 @@ the code is C or C++, and based on that chooses whether to enable
(funcall (major-mode-remap mode)))) (funcall (major-mode-remap mode))))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(c-mode . c-ts-mode)) '(c-mode . c-ts-mode))
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist

View file

@ -284,11 +284,10 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist (add-to-list 'auto-mode-alist
'("\\(?:CMakeLists\\.txt\\|\\.cmake\\)\\'" . cmake-ts-mode-maybe)) '("\\(?:CMakeLists\\.txt\\|\\.cmake\\)\\'" . cmake-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(cmake-mode . cmake-ts-mode))) '(cmake-mode . cmake-ts-mode)))

View file

@ -1287,8 +1287,7 @@ Key bindings:
(derived-mode-add-parents 'csharp-ts-mode '(csharp-mode)) (derived-mode-add-parents 'csharp-ts-mode '(csharp-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(csharp-mode . csharp-ts-mode))) '(csharp-mode . csharp-ts-mode)))

View file

@ -215,7 +215,7 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist (add-to-list 'auto-mode-alist
;; NOTE: We can't use `rx' here, as it breaks bootstrap. ;; NOTE: We can't use `rx' here, as it breaks bootstrap.
;; (rx (or (and (or "Dockerfile" "Containerfile") ;; (rx (or (and (or "Dockerfile" "Containerfile")
@ -225,7 +225,6 @@ is t or contains the mode name."
'("\\(?:\\(?:\\(?:Contain\\|Dock\\)erfile\\)\\(?:\\..*\\)?\\|\\.[Dd]ockerfile\\)\\'" '("\\(?:\\(?:\\(?:Contain\\|Dock\\)erfile\\)\\(?:\\..*\\)?\\|\\.[Dd]ockerfile\\)\\'"
. dockerfile-ts-mode-maybe)) . dockerfile-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(dockerfile-mode . dockerfile-ts-mode))) '(dockerfile-mode . dockerfile-ts-mode)))

View file

@ -815,13 +815,12 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.elixir\\'" . elixir-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.elixir\\'" . elixir-ts-mode-maybe))
(add-to-list 'auto-mode-alist '("\\.ex\\'" . elixir-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.ex\\'" . elixir-ts-mode-maybe))
(add-to-list 'auto-mode-alist '("\\.exs\\'" . elixir-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.exs\\'" . elixir-ts-mode-maybe))
(add-to-list 'auto-mode-alist '("mix\\.lock" . elixir-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("mix\\.lock" . elixir-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(elixir-mode . elixir-ts-mode))) '(elixir-mode . elixir-ts-mode)))

View file

@ -380,10 +380,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(go-mode . go-ts-mode))) '(go-mode . go-ts-mode)))
@ -658,10 +657,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(go-mod-mode . go-mod-ts-mode))) '(go-mod-mode . go-mod-ts-mode)))
@ -763,10 +761,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("/go\\.work\\'" . go-work-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("/go\\.work\\'" . go-work-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(go-work-mode . go-work-ts-mode))) '(go-work-mode . go-work-ts-mode)))

View file

@ -278,12 +278,11 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
;; Both .heex and the deprecated .leex files should work ;; Both .heex and the deprecated .leex files should work
;; with the tree-sitter-heex grammar. ;; with the tree-sitter-heex grammar.
(add-to-list 'auto-mode-alist '("\\.[hl]?eex\\'" . heex-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.[hl]?eex\\'" . heex-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(heex-mode . heex-ts-mode))) '(heex-mode . heex-ts-mode)))

View file

@ -533,8 +533,7 @@ Return nil if there is no name or if NODE is not a defun node."
(derived-mode-add-parents 'java-ts-mode '(java-mode)) (derived-mode-add-parents 'java-ts-mode '(java-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(java-mode . java-ts-mode))) '(java-mode . java-ts-mode)))

View file

@ -4106,8 +4106,7 @@ See `treesit-thing-settings' for more information.")
(derived-mode-add-parents 'js-ts-mode '(js-mode)) (derived-mode-add-parents 'js-ts-mode '(js-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(javascript-mode . js-ts-mode))) '(javascript-mode . js-ts-mode)))

View file

@ -182,8 +182,7 @@ Return nil if there is no name or if NODE is not a defun node."
(derived-mode-add-parents 'json-ts-mode '(json-mode)) (derived-mode-add-parents 'json-ts-mode '(json-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(js-json-mode . json-ts-mode))) '(js-json-mode . json-ts-mode)))

View file

@ -773,8 +773,7 @@ Calls REPORT-FN directly."
(derived-mode-add-parents 'lua-ts-mode '(lua-mode)) (derived-mode-add-parents 'lua-ts-mode '(lua-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(lua-mode . lua-ts-mode))) '(lua-mode . lua-ts-mode)))

View file

@ -1994,7 +1994,7 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list (add-to-list
'auto-mode-alist '("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-ts-mode-maybe)) 'auto-mode-alist '("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-ts-mode-maybe))
(add-to-list (add-to-list
@ -2005,7 +2005,6 @@ is t or contains the mode name."
'interpreter-mode-alist 'interpreter-mode-alist
(cons "php\\(?:-?[34578]\\(?:\\.[0-9]+\\)*\\)?" 'php-ts-mode-maybe)) (cons "php\\(?:-?[34578]\\(?:\\.[0-9]+\\)*\\)?" 'php-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(php-mode . php-ts-mode))) '(php-mode . php-ts-mode)))

View file

@ -7442,8 +7442,7 @@ implementations: `python-mode' and `python-ts-mode'."
(derived-mode-add-parents 'python-ts-mode '(python-mode))) (derived-mode-add-parents 'python-ts-mode '(python-mode)))
;;;###autoload ;;;###autoload
(when (and (fboundp 'treesit-available-p) (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist) ; Emacs 31.1
(boundp 'treesit-major-mode-remap-alist)) ; Emacs 31.1
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(python-mode . python-ts-mode))) '(python-mode . python-ts-mode)))

View file

@ -1278,8 +1278,7 @@ leading double colon is not added."
(derived-mode-add-parents 'ruby-ts-mode '(ruby-mode)) (derived-mode-add-parents 'ruby-ts-mode '(ruby-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(ruby-mode . ruby-ts-mode))) '(ruby-mode . ruby-ts-mode)))

View file

@ -668,10 +668,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(rust-mode . rust-ts-mode))) '(rust-mode . rust-ts-mode)))

View file

@ -1649,8 +1649,7 @@ not written in Bash or sh."
(derived-mode-add-parents 'bash-ts-mode '(sh-mode)) (derived-mode-add-parents 'bash-ts-mode '(sh-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(sh-mode . bash-ts-mode))) '(sh-mode . bash-ts-mode)))

View file

@ -735,10 +735,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(typescript-mode . typescript-ts-mode))) '(typescript-mode . typescript-ts-mode)))
@ -872,10 +871,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(tsx-mode . tsx-ts-mode))) '(tsx-mode . tsx-ts-mode)))

View file

@ -1916,8 +1916,7 @@ can also be used to fill comments.
(derived-mode-add-parents 'css-ts-mode '(css-mode)) (derived-mode-add-parents 'css-ts-mode '(css-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(css-mode . css-ts-mode))) '(css-mode . css-ts-mode)))

View file

@ -422,10 +422,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(markdown-mode . markdown-ts-mode))) '(markdown-mode . markdown-ts-mode)))

View file

@ -599,8 +599,7 @@ Powered by tree-sitter."
(derived-mode-add-parents 'mhtml-ts-mode '(css-mode js-mode)) (derived-mode-add-parents 'mhtml-ts-mode '(css-mode js-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(mhtml-mode . mhtml-ts-mode))) '(mhtml-mode . mhtml-ts-mode)))

View file

@ -173,8 +173,7 @@ Return nil if there is no name or if NODE is not a defun node."
(derived-mode-add-parents 'toml-ts-mode '(toml-mode)) (derived-mode-add-parents 'toml-ts-mode '(toml-mode))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(conf-toml-mode . toml-ts-mode))) '(conf-toml-mode . toml-ts-mode)))

View file

@ -240,10 +240,9 @@ is t or contains the mode name."
(fundamental-mode))) (fundamental-mode)))
;;;###autoload ;;;###autoload
(when (treesit-available-p) (when (boundp 'treesit-major-mode-remap-alist)
(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode-maybe)) (add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode: ;; To be able to toggle between an external package and core ts-mode:
(defvar treesit-major-mode-remap-alist)
(add-to-list 'treesit-major-mode-remap-alist (add-to-list 'treesit-major-mode-remap-alist
'(yaml-mode . yaml-ts-mode))) '(yaml-mode . yaml-ts-mode)))