1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-04 02:51:31 -08:00

New user option 'treesit-enabled-modes' (bug#79180)

* lisp/treesit.el (treesit-enabled-modes): New user option.
* src/treesit.c (treesit-major-mode-remap-alist): New variable.

* lisp/progmodes/c-ts-mode.el:
* lisp/progmodes/csharp-mode.el:
* lisp/progmodes/java-ts-mode.el:
* lisp/progmodes/js.el:
* lisp/progmodes/json-ts-mode.el:
* lisp/progmodes/ruby-ts-mode.el:
* lisp/progmodes/sh-script.el:
* lisp/textmodes/css-mode.el:
* lisp/textmodes/mhtml-ts-mode.el:
* lisp/textmodes/toml-ts-mode.el:
Add ts-mode mapping to 'treesit-major-mode-remap-alist'
for ts-modes that already have the corresponding non-ts mode
association in 'auto-mode-alist'.

* lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode-maybe):
* lisp/progmodes/dockerfile-ts-mode.el (dockerfile-ts-mode-maybe):
* lisp/progmodes/elixir-ts-mode.el (elixir-ts-mode-maybe):
* lisp/progmodes/go-ts-mode.el (go-ts-mode-maybe)
(go-mod-ts-mode-maybe, go-work-ts-mode-maybe):
* lisp/progmodes/heex-ts-mode.el (heex-ts-mode-maybe):
* lisp/progmodes/lua-ts-mode.el (lua-ts-mode-maybe):
* lisp/progmodes/php-ts-mode.el (php-ts-mode-maybe):
* lisp/progmodes/rust-ts-mode.el (rust-ts-mode-maybe):
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode-maybe)
(tsx-ts-mode-maybe):
* lisp/textmodes/markdown-ts-mode.el (markdown-ts-mode-maybe):
* lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode-maybe):
Add a wrapper function to 'auto-mode-alist'
for ts-modes that have no corresponding non-ts mode.
Also add a mapping to 'treesit-major-mode-remap-alist'
for the case when a non-ts mode is installed from an external
source to be able to customize it with 'treesit-enabled-modes'.
This commit is contained in:
Juri Linkov 2025-08-14 19:40:08 +03:00
parent 97e2e90519
commit 0ac3a1f26c
26 changed files with 323 additions and 100 deletions

View file

@ -806,12 +806,24 @@ Return nil if NODE is not a defun node or doesn't have a name."
(derived-mode-add-parents 'elixir-ts-mode '(elixir-mode))
(if (treesit-ready-p 'elixir)
(progn
(add-to-list 'auto-mode-alist '("\\.elixir\\'" . elixir-ts-mode))
(add-to-list 'auto-mode-alist '("\\.ex\\'" . elixir-ts-mode))
(add-to-list 'auto-mode-alist '("\\.exs\\'" . elixir-ts-mode))
(add-to-list 'auto-mode-alist '("mix\\.lock" . elixir-ts-mode))))
;;;###autoload
(defun elixir-ts-mode-maybe ()
"Enable `elixir-ts-mode' when its grammar is available."
(if (or (treesit-language-available-p 'elixir)
(eq treesit-enabled-modes t)
(memq 'elixir-ts-mode treesit-enabled-modes))
(elixir-ts-mode)
(fundamental-mode)))
;;;###autoload
(when (treesit-available-p)
(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 '("\\.exs\\'" . 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:
(add-to-list 'treesit-major-mode-remap-alist
'(elixir-mode . elixir-ts-mode)))
(provide 'elixir-ts-mode)