diff --git a/lisp/files.el b/lisp/files.el index 9c105dbe1a5..9f256695011 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3059,9 +3059,13 @@ auto-mode-alist ("\\.dbk\\'" . xml-mode) ("\\.dtd\\'" . sgml-mode) ("\\.ds\\(ss\\)?l\\'" . dsssl-mode) - ("\\.js[mx]?\\'" . javascript-mode) + ("\\.js[mx]?\\'" . ,(if (treesit-available-p) + 'js-ts-mode + 'javascript-mode)) ;; https://en.wikipedia.org/wiki/.har - ("\\.har\\'" . javascript-mode) + ("\\.har\\'" . ,(if (treesit-available-p) + 'js-ts-mode + 'javascript-mode)) ("\\.json\\'" . js-json-mode) ("\\.[ds]?va?h?\\'" . verilog-mode) ("\\.by\\'" . bovine-grammar-mode) diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el index 3823c553fda..5b89fe917c2 100644 --- a/lisp/progmodes/c-ts-mode.el +++ b/lisp/progmodes/c-ts-mode.el @@ -35,12 +35,6 @@ ;; To use these modes by default, assuming you have the respective ;; tree-sitter grammars available, do one of the following: ;; -;; - If you have both C and C++ grammars installed, add -;; -;; (require 'c-ts-mode) -;; -;; to your init file. -;; ;; - Add one or mode of the following to your init file: ;; ;; (add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode)) @@ -1539,21 +1533,6 @@ c-or-c++-ts-mode 'c-ts-mode))) (funcall (major-mode-remap mode)))) -;; The entries for C++ must come first to prevent *.c files be taken -;; as C++ on case-insensitive filesystems, since *.C files are C++, -;; not C. -(if (treesit-ready-p 'cpp) - (add-to-list 'major-mode-remap-defaults - '(c++-mode . c++-ts-mode))) - -(when (treesit-ready-p 'c) - (add-to-list 'major-mode-remap-defaults '(c++-mode . c++-ts-mode)) - (add-to-list 'major-mode-remap-defaults '(c-mode . c-ts-mode))) - -(when (and (treesit-ready-p 'cpp) - (treesit-ready-p 'c)) - (add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode))) - (when (and c-ts-mode-enable-doxygen (not (treesit-ready-p 'doxygen t))) (message "Doxygen syntax highlighting can't be enabled, please install the language grammar.")) diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index c5bb075c7f6..867d47ee0a2 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -3377,22 +3377,6 @@ c-submit-bug-report (insert (format "Buffer Style: %s\nc-emacs-features: %s\n" style c-features))))))) - -;; Make entries in `major-mode-remap-defaults' to ensure that when CC -;; Mode has been loaded, the symbols `c-mode' etc., will call CC Mode's -;; modes rather than c-ts-mode etc.. -(when (boundp 'major-mode-remap-defaults) - (add-to-list 'major-mode-remap-defaults '(c++-mode . c++-ts-mode)) - (add-to-list 'major-mode-remap-defaults '(c-mode . c-ts-mode)) - (add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode)) - (let (entry) - (dolist (mode '(c-mode c++-mode c-or-c++-mode)) - (if (and (setq entry (assq mode major-mode-remap-defaults)) - (null (cdr entry))) - (setq major-mode-remap-defaults - (delq entry major-mode-remap-defaults))) - (push (cons mode nil) major-mode-remap-defaults)))) - (cc-provide 'cc-mode) diff --git a/lisp/progmodes/cmake-ts-mode.el b/lisp/progmodes/cmake-ts-mode.el index 597ef69d9b8..f40147a94b0 100644 --- a/lisp/progmodes/cmake-ts-mode.el +++ b/lisp/progmodes/cmake-ts-mode.el @@ -244,7 +244,8 @@ cmake-ts-mode (derived-mode-add-parents 'cmake-ts-mode '(cmake-mode)) -(if (treesit-ready-p 'cmake) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\(?:CMakeLists\\.txt\\|\\.cmake\\)\\'" . cmake-ts-mode))) diff --git a/lisp/progmodes/csharp-mode.el b/lisp/progmodes/csharp-mode.el index b86555b1d87..dbf169a048c 100644 --- a/lisp/progmodes/csharp-mode.el +++ b/lisp/progmodes/csharp-mode.el @@ -1089,9 +1089,11 @@ csharp-ts-mode ("Struct" "\\`struct_declaration\\'" nil nil) ("Method" "\\`method_declaration\\'" nil nil))) - (treesit-major-mode-setup) + (treesit-major-mode-setup)) - (add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-ts-mode))) +;;;###autoload +(if (treesit-available-p) + (add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-ts-mode))) (derived-mode-add-parents 'csharp-ts-mode '(csharp-mode)) diff --git a/lisp/progmodes/dockerfile-ts-mode.el b/lisp/progmodes/dockerfile-ts-mode.el index 42fa7482a87..2d33c6c2c65 100644 --- a/lisp/progmodes/dockerfile-ts-mode.el +++ b/lisp/progmodes/dockerfile-ts-mode.el @@ -167,7 +167,8 @@ dockerfile-ts-mode (derived-mode-add-parents 'dockerfile-ts-mode '(dockerfile-mode)) -(if (treesit-ready-p 'dockerfile) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist ;; NOTE: We can't use `rx' here, as it breaks bootstrap. '("\\(?:Dockerfile\\(?:\\..*\\)?\\|\\.[Dd]ockerfile\\)\\'" diff --git a/lisp/progmodes/elixir-ts-mode.el b/lisp/progmodes/elixir-ts-mode.el index cacdb266298..a3b9f7d5611 100644 --- a/lisp/progmodes/elixir-ts-mode.el +++ b/lisp/progmodes/elixir-ts-mode.el @@ -755,7 +755,8 @@ elixir-ts-mode (derived-mode-add-parents 'elixir-ts-mode '(elixir-mode)) -(if (treesit-ready-p 'elixir) +;;;###autoload +(if (treesit-available-p) (progn (add-to-list 'auto-mode-alist '("\\.elixir\\'" . elixir-ts-mode)) (add-to-list 'auto-mode-alist '("\\.ex\\'" . elixir-ts-mode)) diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el index 86e74ad58a8..3e1bc4bea40 100644 --- a/lisp/progmodes/go-ts-mode.el +++ b/lisp/progmodes/go-ts-mode.el @@ -305,7 +305,8 @@ go-ts-mode (derived-mode-add-parents 'go-ts-mode '(go-mode)) -(if (treesit-ready-p 'go) +;;;###autoload +(if (treesit-available-p) ;; FIXME: Should we instead put `go-mode' in `auto-mode-alist' ;; and then use `major-mode-remap-defaults' to map it to `go-ts-mode'? (add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode))) @@ -562,7 +563,8 @@ go-mod-ts-mode (derived-mode-add-parents 'go-mod-ts-mode '(go-mod-mode)) -(if (treesit-ready-p 'gomod) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode))) (provide 'go-ts-mode) diff --git a/lisp/progmodes/heex-ts-mode.el b/lisp/progmodes/heex-ts-mode.el index 84fd513525c..3f26f0a9b14 100644 --- a/lisp/progmodes/heex-ts-mode.el +++ b/lisp/progmodes/heex-ts-mode.el @@ -191,7 +191,8 @@ heex-ts-mode (derived-mode-add-parents 'heex-ts-mode '(heex-mode)) -(if (treesit-ready-p 'heex) +;;;###autoload +(if (treesit-available-p) ;; Both .heex and the deprecated .leex files should work ;; with the tree-sitter-heex grammar. (add-to-list 'auto-mode-alist '("\\.[hl]?eex\\'" . heex-ts-mode))) diff --git a/lisp/progmodes/java-ts-mode.el b/lisp/progmodes/java-ts-mode.el index 177f914160c..860cb433f71 100644 --- a/lisp/progmodes/java-ts-mode.el +++ b/lisp/progmodes/java-ts-mode.el @@ -436,7 +436,8 @@ java-ts-mode (derived-mode-add-parents 'java-ts-mode '(java-mode)) -(if (treesit-ready-p 'java) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.java\\'" . java-ts-mode))) (when (and java-ts-mode-enable-doxygen (not (treesit-ready-p 'doxygen t))) diff --git a/lisp/progmodes/js.el b/lisp/progmodes/js.el index f74b8ab1c46..a4d4399012c 100644 --- a/lisp/progmodes/js.el +++ b/lisp/progmodes/js.el @@ -3961,10 +3961,7 @@ js-ts-mode "method_definition") eos) nil nil))) - (treesit-major-mode-setup) - - (add-to-list 'auto-mode-alist - '("\\(\\.js[mx]\\|\\.har\\)\\'" . js-ts-mode)))) + (treesit-major-mode-setup))) (derived-mode-add-parents 'js-ts-mode '(js-mode)) diff --git a/lisp/progmodes/json-ts-mode.el b/lisp/progmodes/json-ts-mode.el index 7409c6be833..e0d8cf72841 100644 --- a/lisp/progmodes/json-ts-mode.el +++ b/lisp/progmodes/json-ts-mode.el @@ -166,7 +166,8 @@ json-ts-mode (derived-mode-add-parents 'json-ts-mode '(json-mode)) -(if (treesit-ready-p 'json) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.json\\'" . json-ts-mode))) diff --git a/lisp/progmodes/lua-ts-mode.el b/lisp/progmodes/lua-ts-mode.el index 20bc1f3e158..58328332e68 100644 --- a/lisp/progmodes/lua-ts-mode.el +++ b/lisp/progmodes/lua-ts-mode.el @@ -837,7 +837,8 @@ lua-ts-mode (derived-mode-add-parents 'lua-ts-mode '(lua-mode)) -(when (treesit-ready-p 'lua) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-ts-mode))) (provide 'lua-ts-mode) diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el index 07a0c266d78..b090da01ce8 100644 --- a/lisp/progmodes/php-ts-mode.el +++ b/lisp/progmodes/php-ts-mode.el @@ -1824,7 +1824,8 @@ php-ts-mode-kill-process (with-current-buffer php-ts-mode-inferior-php-buffer (kill-buffer-and-window))) -(when (treesit-ready-p 'php) +;;;###autoload +(when (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-ts-mode)) (add-to-list diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 283a545bfb4..f8903771aa2 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -287,9 +287,13 @@ python--auto-mode-alist-regexp eos)) ;;;###autoload -(add-to-list 'auto-mode-alist (cons python--auto-mode-alist-regexp 'python-mode)) +(add-to-list 'auto-mode-alist + (cons python--auto-mode-alist-regexp + (if (treesit-available-p) 'python-ts-mode 'python-mode))) ;;;###autoload -(add-to-list 'interpreter-mode-alist (cons (purecopy "python[0-9.]*") 'python-mode)) +(add-to-list 'interpreter-mode-alist + (cons (purecopy "python[0-9.]*") + (if (treesit-available-p) 'python-ts-mode 'python-mode))) (defgroup python nil "Python Language's flying circus support for Emacs." diff --git a/lisp/progmodes/ruby-ts-mode.el b/lisp/progmodes/ruby-ts-mode.el index aff0b8911b9..646de8a4ec3 100644 --- a/lisp/progmodes/ruby-ts-mode.el +++ b/lisp/progmodes/ruby-ts-mode.el @@ -1237,7 +1237,8 @@ ruby-ts-mode (derived-mode-add-parents 'ruby-ts-mode '(ruby-mode)) -(if (treesit-ready-p 'ruby) +;;;###autoload +(if (treesit-available-p) (add-to-list 'major-mode-remap-defaults '(ruby-mode . ruby-ts-mode))) diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el index e52ea3b125a..4ee671e16e4 100644 --- a/lisp/progmodes/rust-ts-mode.el +++ b/lisp/progmodes/rust-ts-mode.el @@ -566,7 +566,8 @@ rust-ts-mode (derived-mode-add-parents 'rust-ts-mode '(rust-mode)) -(if (treesit-ready-p 'rust) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode))) (provide 'rust-ts-mode) diff --git a/lisp/progmodes/typescript-ts-mode.el b/lisp/progmodes/typescript-ts-mode.el index ef5dbe51ada..bfb7f1afc84 100644 --- a/lisp/progmodes/typescript-ts-mode.el +++ b/lisp/progmodes/typescript-ts-mode.el @@ -535,7 +535,8 @@ typescript-ts-mode (derived-mode-add-parents 'typescript-ts-mode '(typescript-mode)) -(if (treesit-ready-p 'typescript) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode))) ;;;###autoload @@ -631,7 +632,8 @@ tsx-ts--syntax-propertize-captures (put-text-property ns (1+ ns) 'syntax-table syntax) (put-text-property (1- ne) ne 'syntax-table syntax)))) -(if (treesit-ready-p 'tsx) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode))) (provide 'typescript-ts-mode) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index c8da28187ee..04e1cce807e 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1826,12 +1826,14 @@ css-ts-mode (setq-local treesit-simple-imenu-settings `(( nil ,(rx bos (or "rule_set" "media_statement") eos) nil nil))) - (treesit-major-mode-setup) - - (add-to-list 'auto-mode-alist '("\\.css\\'" . css-ts-mode)))) + (treesit-major-mode-setup))) (derived-mode-add-parents 'css-ts-mode '(css-mode)) +;;;###autoload +(if (treesit-available-p) + (add-to-list 'auto-mode-alist '("\\.css\\'" . css-ts-mode))) + ;;;###autoload (define-derived-mode css-mode css-base-mode "CSS" "Major mode to edit Cascading Style Sheets (CSS). diff --git a/lisp/textmodes/html-ts-mode.el b/lisp/textmodes/html-ts-mode.el index f78fbdde1da..c21d187be28 100644 --- a/lisp/textmodes/html-ts-mode.el +++ b/lisp/textmodes/html-ts-mode.el @@ -136,7 +136,8 @@ html-ts-mode (derived-mode-add-parents 'html-ts-mode '(html-mode)) -(if (treesit-ready-p 'html) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.html\\'" . html-ts-mode))) (provide 'html-ts-mode) diff --git a/lisp/textmodes/toml-ts-mode.el b/lisp/textmodes/toml-ts-mode.el index 806f045c23b..fcb9a056353 100644 --- a/lisp/textmodes/toml-ts-mode.el +++ b/lisp/textmodes/toml-ts-mode.el @@ -155,7 +155,8 @@ toml-ts-mode (derived-mode-add-parents 'toml-ts-mode '(toml-mode)) -(if (treesit-ready-p 'toml) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode))) (provide 'toml-ts-mode) diff --git a/lisp/textmodes/yaml-ts-mode.el b/lisp/textmodes/yaml-ts-mode.el index 42d7c2e1798..b39d32148c0 100644 --- a/lisp/textmodes/yaml-ts-mode.el +++ b/lisp/textmodes/yaml-ts-mode.el @@ -171,7 +171,8 @@ yaml-ts-mode (derived-mode-add-parents 'yaml-ts-mode '(yaml-mode)) -(if (treesit-ready-p 'yaml) +;;;###autoload +(if (treesit-available-p) (add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode))) (provide 'yaml-ts-mode)