1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -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

@ -359,10 +359,21 @@
(derived-mode-add-parents 'go-ts-mode '(go-mode))
(if (treesit-ready-p 'go)
;; 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)))
;;;###autoload
(defun go-ts-mode-maybe ()
"Enable `go-ts-mode' when its grammar is available."
(if (or (treesit-language-available-p 'go)
(eq treesit-enabled-modes t)
(memq 'go-ts-mode treesit-enabled-modes))
(go-ts-mode)
(fundamental-mode)))
;;;###autoload
(when (treesit-available-p)
(add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode-maybe))
;; To be able to toggle between an external package and core ts-mode:
(add-to-list 'treesit-major-mode-remap-alist
'(go-mode . go-ts-mode)))
(defun go-ts-mode--defun-name (node &optional skip-prefix)
"Return the defun name of NODE.
@ -622,8 +633,21 @@ what the parent of the node would be if it were a node."
(derived-mode-add-parents 'go-mod-ts-mode '(go-mod-mode))
(if (treesit-ready-p 'gomod t)
(add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode)))
;;;###autoload
(defun go-mod-ts-mode-maybe ()
"Enable `go-mod-ts-mode' when its grammar is available."
(if (or (treesit-language-available-p 'gomod)
(eq treesit-enabled-modes t)
(memq 'go-mod-ts-mode treesit-enabled-modes))
(go-mod-ts-mode)
(fundamental-mode)))
;;;###autoload
(when (treesit-available-p)
(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:
(add-to-list 'treesit-major-mode-remap-alist
'(go-mod-mode . go-mod-ts-mode)))
;;;; go.work support.
@ -711,7 +735,20 @@ what the parent of the node would be if it were a node."
(treesit-major-mode-setup)))
;;;###autoload
(add-to-list 'auto-mode-alist '("/go\\.work\\'" . go-work-ts-mode))
(defun go-work-ts-mode-maybe ()
"Enable `go-work-ts-mode' when its grammar is available."
(if (or (treesit-language-available-p 'gowork)
(eq treesit-enabled-modes t)
(memq 'go-work-ts-mode treesit-enabled-modes))
(go-work-ts-mode)
(fundamental-mode)))
;;;###autoload
(when (treesit-available-p)
(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:
(add-to-list 'treesit-major-mode-remap-alist
'(go-work-mode . go-work-ts-mode)))
(provide 'go-ts-mode)