mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 14:30:50 -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:
parent
97e2e90519
commit
0ac3a1f26c
26 changed files with 323 additions and 100 deletions
6
etc/NEWS
6
etc/NEWS
|
|
@ -722,6 +722,12 @@ the default UI you get, i.e., when 'register-use-preview' is 'traditional'.
|
||||||
|
|
||||||
** Tree-sitter
|
** Tree-sitter
|
||||||
|
|
||||||
|
*** New user option 'treesit-enabled-modes'.
|
||||||
|
You can customize it either to t to enable all available ts-modes,
|
||||||
|
or to select a list of ts-modes to enable. Depending on customization,
|
||||||
|
it modifies the variable 'major-mode-remap-alist' from the corresponding
|
||||||
|
variable 'treesit-major-mode-remap-alist' prepared by ts-mode packages.
|
||||||
|
|
||||||
*** New user option 'treesit-auto-install-grammar'.
|
*** New user option 'treesit-auto-install-grammar'.
|
||||||
It controls the automatic installation of tree-sitter grammar libraries
|
It controls the automatic installation of tree-sitter grammar libraries
|
||||||
needed for tree-sitter based modes, if these grammar libraries are not
|
needed for tree-sitter based modes, if these grammar libraries are not
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,9 @@
|
||||||
;;
|
;;
|
||||||
;; will turn on the c++-ts-mode for C++ source files.
|
;; will turn on the c++-ts-mode for C++ source files.
|
||||||
;;
|
;;
|
||||||
;; - If you have both C and C++ grammars installed, add
|
;; - If you have both C and C++ grammars installed, customize
|
||||||
;;
|
;; 'treesit-enabled-modes' and select 'c-ts-mode',
|
||||||
;; (load "c-ts-mode")
|
;; 'c++-mode', 'c-or-c++-mode'.
|
||||||
;;
|
|
||||||
;; to your init file.
|
|
||||||
;;
|
;;
|
||||||
;; You can also turn on these modes manually in a buffer. Doing so
|
;; You can also turn on these modes manually in a buffer. Doing so
|
||||||
;; will set up Emacs to use the C/C++ modes defined here for other
|
;; will set up Emacs to use the C/C++ modes defined here for other
|
||||||
|
|
@ -1675,21 +1673,14 @@ the code is C or C++, and based on that chooses whether to enable
|
||||||
'c-ts-mode)))
|
'c-ts-mode)))
|
||||||
(funcall (major-mode-remap mode))))
|
(funcall (major-mode-remap mode))))
|
||||||
|
|
||||||
(when (treesit-ready-p 'cpp)
|
;;;###autoload
|
||||||
(setq major-mode-remap-defaults
|
(when (treesit-available-p)
|
||||||
(assq-delete-all 'c++-mode major-mode-remap-defaults))
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
(add-to-list 'major-mode-remap-defaults '(c++-mode . c++-ts-mode)))
|
'(c-mode . c-ts-mode))
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
(when (treesit-ready-p 'c)
|
'(c++-mode . c++-ts-mode))
|
||||||
(setq major-mode-remap-defaults
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
(assq-delete-all 'c-mode major-mode-remap-defaults))
|
'(c-or-c++-mode . c-or-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))
|
|
||||||
(setq major-mode-remap-defaults
|
|
||||||
(assq-delete-all 'c-or-c++-mode major-mode-remap-defaults))
|
|
||||||
(add-to-list 'major-mode-remap-defaults '(c-or-c++-mode . c-or-c++-ts-mode)))
|
|
||||||
|
|
||||||
(provide 'c-ts-mode)
|
(provide 'c-ts-mode)
|
||||||
(provide 'c++-ts-mode)
|
(provide 'c++-ts-mode)
|
||||||
|
|
|
||||||
|
|
@ -255,9 +255,22 @@ Return nil if there is no name or if NODE is not a defun node."
|
||||||
|
|
||||||
(derived-mode-add-parents 'cmake-ts-mode '(cmake-mode))
|
(derived-mode-add-parents 'cmake-ts-mode '(cmake-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'cmake)
|
;;;###autoload
|
||||||
|
(defun cmake-ts-mode-maybe ()
|
||||||
|
"Enable `cmake-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'cmake)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'cmake-ts-mode treesit-enabled-modes))
|
||||||
|
(cmake-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
(add-to-list 'auto-mode-alist
|
(add-to-list 'auto-mode-alist
|
||||||
'("\\(?:CMakeLists\\.txt\\|\\.cmake\\)\\'" . cmake-ts-mode)))
|
'("\\(?:CMakeLists\\.txt\\|\\.cmake\\)\\'" . cmake-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(cmake-mode . cmake-ts-mode)))
|
||||||
|
|
||||||
(provide 'cmake-ts-mode)
|
(provide 'cmake-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1219,12 +1219,15 @@ Key bindings:
|
||||||
"local_function_statement")
|
"local_function_statement")
|
||||||
eos))
|
eos))
|
||||||
|
|
||||||
(treesit-major-mode-setup)
|
(treesit-major-mode-setup))
|
||||||
|
|
||||||
(add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-ts-mode)))
|
|
||||||
|
|
||||||
(derived-mode-add-parents 'csharp-ts-mode '(csharp-mode))
|
(derived-mode-add-parents 'csharp-ts-mode '(csharp-mode))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(csharp-mode . csharp-ts-mode)))
|
||||||
|
|
||||||
(provide 'csharp-mode)
|
(provide 'csharp-mode)
|
||||||
|
|
||||||
;;; csharp-mode.el ends here
|
;;; csharp-mode.el ends here
|
||||||
|
|
|
||||||
|
|
@ -202,11 +202,24 @@ Return nil if there is no name or if NODE is not a stage node."
|
||||||
|
|
||||||
(derived-mode-add-parents 'dockerfile-ts-mode '(dockerfile-mode))
|
(derived-mode-add-parents 'dockerfile-ts-mode '(dockerfile-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'dockerfile)
|
;;;###autoload
|
||||||
|
(defun dockerfile-ts-mode-maybe ()
|
||||||
|
"Enable `dockerfile-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'dockerfile)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'dockerfile-ts-mode treesit-enabled-modes))
|
||||||
|
(dockerfile-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
(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.
|
||||||
'("\\(?:Dockerfile\\(?:\\..*\\)?\\|\\.[Dd]ockerfile\\)\\'"
|
'("\\(?:Dockerfile\\(?:\\..*\\)?\\|\\.[Dd]ockerfile\\)\\'"
|
||||||
. dockerfile-ts-mode)))
|
. dockerfile-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(dockerfile-mode . dockerfile-ts-mode)))
|
||||||
|
|
||||||
(provide 'dockerfile-ts-mode)
|
(provide 'dockerfile-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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))
|
(derived-mode-add-parents 'elixir-ts-mode '(elixir-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'elixir)
|
;;;###autoload
|
||||||
(progn
|
(defun elixir-ts-mode-maybe ()
|
||||||
(add-to-list 'auto-mode-alist '("\\.elixir\\'" . elixir-ts-mode))
|
"Enable `elixir-ts-mode' when its grammar is available."
|
||||||
(add-to-list 'auto-mode-alist '("\\.ex\\'" . elixir-ts-mode))
|
(if (or (treesit-language-available-p 'elixir)
|
||||||
(add-to-list 'auto-mode-alist '("\\.exs\\'" . elixir-ts-mode))
|
(eq treesit-enabled-modes t)
|
||||||
(add-to-list 'auto-mode-alist '("mix\\.lock" . elixir-ts-mode))))
|
(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)
|
(provide 'elixir-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -359,10 +359,21 @@
|
||||||
|
|
||||||
(derived-mode-add-parents 'go-ts-mode '(go-mode))
|
(derived-mode-add-parents 'go-ts-mode '(go-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'go)
|
;;;###autoload
|
||||||
;; FIXME: Should we instead put `go-mode' in `auto-mode-alist'
|
(defun go-ts-mode-maybe ()
|
||||||
;; and then use `major-mode-remap-defaults' to map it to `go-ts-mode'?
|
"Enable `go-ts-mode' when its grammar is available."
|
||||||
(add-to-list 'auto-mode-alist '("\\.go\\'" . go-ts-mode)))
|
(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)
|
(defun go-ts-mode--defun-name (node &optional skip-prefix)
|
||||||
"Return the defun name of NODE.
|
"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))
|
(derived-mode-add-parents 'go-mod-ts-mode '(go-mod-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'gomod t)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode)))
|
(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.
|
;;;; go.work support.
|
||||||
|
|
||||||
|
|
@ -711,7 +735,20 @@ what the parent of the node would be if it were a node."
|
||||||
(treesit-major-mode-setup)))
|
(treesit-major-mode-setup)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###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)
|
(provide 'go-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -265,10 +265,23 @@ Return nil if NODE is not a defun node or doesn't have a name."
|
||||||
|
|
||||||
(derived-mode-add-parents 'heex-ts-mode '(heex-mode))
|
(derived-mode-add-parents 'heex-ts-mode '(heex-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'heex)
|
;;;###autoload
|
||||||
|
(defun heex-ts-mode-maybe ()
|
||||||
|
"Enable `heex-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'heex)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'heex-ts-mode treesit-enabled-modes))
|
||||||
|
(heex-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
;; 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)))
|
(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:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(heex-mode . heex-ts-mode)))
|
||||||
|
|
||||||
(provide 'heex-ts-mode)
|
(provide 'heex-ts-mode)
|
||||||
;;; heex-ts-mode.el ends here
|
;;; heex-ts-mode.el ends here
|
||||||
|
|
|
||||||
|
|
@ -524,8 +524,10 @@ 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))
|
||||||
|
|
||||||
(if (treesit-ready-p 'java)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.java\\'" . java-ts-mode)))
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(java-mode . java-ts-mode)))
|
||||||
|
|
||||||
(provide 'java-ts-mode)
|
(provide 'java-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4105,13 +4105,15 @@ See `treesit-thing-settings' for more information.")
|
||||||
;; Outline minor mode
|
;; Outline minor mode
|
||||||
(setq-local treesit-outline-predicate js-ts-mode--outline-predicate)
|
(setq-local treesit-outline-predicate js-ts-mode--outline-predicate)
|
||||||
|
|
||||||
(treesit-major-mode-setup)
|
(treesit-major-mode-setup)))
|
||||||
|
|
||||||
(add-to-list 'auto-mode-alist
|
|
||||||
'("\\(\\.js[mx]?\\|\\.har\\)\\'" . js-ts-mode))))
|
|
||||||
|
|
||||||
(derived-mode-add-parents 'js-ts-mode '(js-mode))
|
(derived-mode-add-parents 'js-ts-mode '(js-mode))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(javascript-mode . js-ts-mode)))
|
||||||
|
|
||||||
(defvar js-ts--s-p-query
|
(defvar js-ts--s-p-query
|
||||||
(when (treesit-available-p)
|
(when (treesit-available-p)
|
||||||
(treesit-query-compile 'javascript
|
(treesit-query-compile 'javascript
|
||||||
|
|
|
||||||
|
|
@ -181,9 +181,10 @@ 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))
|
||||||
|
|
||||||
(if (treesit-ready-p 'json)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist
|
(when (treesit-available-p)
|
||||||
'("\\.json\\'" . json-ts-mode)))
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(js-json-mode . json-ts-mode)))
|
||||||
|
|
||||||
(provide 'json-ts-mode)
|
(provide 'json-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -769,9 +769,22 @@ Calls REPORT-FN directly."
|
||||||
|
|
||||||
(derived-mode-add-parents 'lua-ts-mode '(lua-mode))
|
(derived-mode-add-parents 'lua-ts-mode '(lua-mode))
|
||||||
|
|
||||||
(when (treesit-ready-p 'lua)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-ts-mode))
|
(defun lua-ts-mode-maybe ()
|
||||||
(add-to-list 'interpreter-mode-alist '("\\<lua\\(?:jit\\)?" . lua-ts-mode)))
|
"Enable `lua-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'lua)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'lua-ts-mode treesit-enabled-modes))
|
||||||
|
(lua-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-ts-mode-maybe))
|
||||||
|
(add-to-list 'interpreter-mode-alist '("\\<lua\\(?:jit\\)?" . lua-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(lua-mode . lua-ts-mode)))
|
||||||
|
|
||||||
(provide 'lua-ts-mode)
|
(provide 'lua-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1922,16 +1922,29 @@ file to use."
|
||||||
(with-current-buffer php-ts-mode-inferior-php-buffer
|
(with-current-buffer php-ts-mode-inferior-php-buffer
|
||||||
(kill-buffer-and-window)))
|
(kill-buffer-and-window)))
|
||||||
|
|
||||||
(when (treesit-ready-p 'php)
|
;;;###autoload
|
||||||
|
(defun php-ts-mode-maybe ()
|
||||||
|
"Enable `php-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'php)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'php-ts-mode treesit-enabled-modes))
|
||||||
|
(php-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
(add-to-list
|
(add-to-list
|
||||||
'auto-mode-alist '("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-ts-mode))
|
'auto-mode-alist '("\\.\\(?:php[s345]?\\|phtml\\)\\'" . php-ts-mode-maybe))
|
||||||
(add-to-list
|
(add-to-list
|
||||||
'auto-mode-alist '("\\.\\(?:php\\|inc\\|stub\\)\\'" . php-ts-mode))
|
'auto-mode-alist '("\\.\\(?:php\\|inc\\|stub\\)\\'" . php-ts-mode-maybe))
|
||||||
(add-to-list
|
(add-to-list
|
||||||
'auto-mode-alist '("/\\.php_cs\\(?:\\.dist\\)?\\'" . php-ts-mode))
|
'auto-mode-alist '("/\\.php_cs\\(?:\\.dist\\)?\\'" . php-ts-mode-maybe))
|
||||||
(add-to-list
|
(add-to-list
|
||||||
'interpreter-mode-alist
|
'interpreter-mode-alist
|
||||||
(cons "php\\(?:-?[34578]\\(?:\\.[0-9]+\\)*\\)?" 'php-ts-mode)))
|
(cons "php\\(?:-?[34578]\\(?:\\.[0-9]+\\)*\\)?" 'php-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(php-mode . php-ts-mode)))
|
||||||
|
|
||||||
(provide 'php-ts-mode)
|
(provide 'php-ts-mode)
|
||||||
;;; php-ts-mode.el ends here
|
;;; php-ts-mode.el ends here
|
||||||
|
|
|
||||||
|
|
@ -2748,10 +2748,6 @@ Currently there are `ruby-mode' and `ruby-ts-mode'."
|
||||||
(dolist (name (list "ruby" "rbx" "jruby" "j?ruby\\(?:[0-9.]+\\)"))
|
(dolist (name (list "ruby" "rbx" "jruby" "j?ruby\\(?:[0-9.]+\\)"))
|
||||||
(add-to-list 'interpreter-mode-alist (cons name 'ruby-mode)))
|
(add-to-list 'interpreter-mode-alist (cons name 'ruby-mode)))
|
||||||
|
|
||||||
;; See ruby-ts-mode.el for why we do this.
|
|
||||||
(setq major-mode-remap-defaults
|
|
||||||
(assq-delete-all 'ruby-mode major-mode-remap-defaults))
|
|
||||||
|
|
||||||
(provide 'ruby-mode)
|
(provide 'ruby-mode)
|
||||||
|
|
||||||
;;; ruby-mode.el ends here
|
;;; ruby-mode.el ends here
|
||||||
|
|
|
||||||
|
|
@ -68,11 +68,8 @@
|
||||||
;;
|
;;
|
||||||
;; will turn on the ruby-ts-mode for Ruby source files.
|
;; will turn on the ruby-ts-mode for Ruby source files.
|
||||||
;;
|
;;
|
||||||
;; - If you have the Ruby grammar installed, add
|
;; - If you have the Ruby grammar installed, customize
|
||||||
;;
|
;; 'treesit-enabled-modes' and add 'ruby-ts-mode' to it.
|
||||||
;; (load "ruby-ts-mode")
|
|
||||||
;;
|
|
||||||
;; to your init file.
|
|
||||||
;;
|
;;
|
||||||
;; You can also turn on this mode manually in a buffer.
|
;; You can also turn on this mode manually in a buffer.
|
||||||
|
|
||||||
|
|
@ -1280,10 +1277,9 @@ leading double colon is not added."
|
||||||
|
|
||||||
(derived-mode-add-parents 'ruby-ts-mode '(ruby-mode))
|
(derived-mode-add-parents 'ruby-ts-mode '(ruby-mode))
|
||||||
|
|
||||||
(when (treesit-ready-p 'ruby)
|
;;;###autoload
|
||||||
(setq major-mode-remap-defaults
|
(when (treesit-available-p)
|
||||||
(assq-delete-all 'ruby-mode major-mode-remap-defaults))
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
(add-to-list 'major-mode-remap-defaults
|
|
||||||
'(ruby-mode . ruby-ts-mode)))
|
'(ruby-mode . ruby-ts-mode)))
|
||||||
|
|
||||||
(provide 'ruby-ts-mode)
|
(provide 'ruby-ts-mode)
|
||||||
|
|
|
||||||
|
|
@ -654,8 +654,21 @@ See `prettify-symbols-compose-predicate'."
|
||||||
|
|
||||||
(derived-mode-add-parents 'rust-ts-mode '(rust-mode))
|
(derived-mode-add-parents 'rust-ts-mode '(rust-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'rust)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode)))
|
(defun rust-ts-mode-maybe ()
|
||||||
|
"Enable `rust-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'rust)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'rust-ts-mode treesit-enabled-modes))
|
||||||
|
(rust-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(rust-mode . rust-ts-mode)))
|
||||||
|
|
||||||
(provide 'rust-ts-mode)
|
(provide 'rust-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1648,6 +1648,11 @@ 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
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(sh-mode . bash-ts-mode)))
|
||||||
|
|
||||||
(advice-add 'bash-ts-mode :around #'sh--redirect-bash-ts-mode
|
(advice-add 'bash-ts-mode :around #'sh--redirect-bash-ts-mode
|
||||||
;; Give it lower precedence than normal advice, so other
|
;; Give it lower precedence than normal advice, so other
|
||||||
;; advices take precedence over it.
|
;; advices take precedence over it.
|
||||||
|
|
|
||||||
|
|
@ -722,8 +722,21 @@ This mode is intended to be inherited by concrete major modes."
|
||||||
|
|
||||||
(derived-mode-add-parents 'typescript-ts-mode '(typescript-mode))
|
(derived-mode-add-parents 'typescript-ts-mode '(typescript-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'typescript)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode)))
|
(defun typescript-ts-mode-maybe ()
|
||||||
|
"Enable `typescript-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'typescript)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'typescript-ts-mode treesit-enabled-modes))
|
||||||
|
(typescript-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(typescript-mode . typescript-ts-mode)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-derived-mode tsx-ts-mode typescript-ts-base-mode "TypeScript[TSX]"
|
(define-derived-mode tsx-ts-mode typescript-ts-base-mode "TypeScript[TSX]"
|
||||||
|
|
@ -842,8 +855,21 @@ at least 3 (which is the default value)."
|
||||||
((equal (match-string 0) ">") ")>")
|
((equal (match-string 0) ">") ")>")
|
||||||
(t ".")))))))))))
|
(t ".")))))))))))
|
||||||
|
|
||||||
(if (treesit-ready-p 'tsx)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode)))
|
(defun tsx-ts-mode-maybe ()
|
||||||
|
"Enable `tsx-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'tsx)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'tsx-ts-mode treesit-enabled-modes))
|
||||||
|
(tsx-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . tsx-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(tsx-mode . tsx-ts-mode)))
|
||||||
|
|
||||||
(provide 'typescript-ts-mode)
|
(provide 'typescript-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1911,12 +1911,15 @@ can also be used to fill comments.
|
||||||
(setq-local treesit-outline-predicate css-ts-mode--outline-predicate)
|
(setq-local treesit-outline-predicate css-ts-mode--outline-predicate)
|
||||||
(setq-local treesit-thing-settings css--treesit-thing-settings)
|
(setq-local treesit-thing-settings css--treesit-thing-settings)
|
||||||
|
|
||||||
(treesit-major-mode-setup)
|
(treesit-major-mode-setup)))
|
||||||
|
|
||||||
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-ts-mode))))
|
|
||||||
|
|
||||||
(derived-mode-add-parents 'css-ts-mode '(css-mode))
|
(derived-mode-add-parents 'css-ts-mode '(css-mode))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(css-mode . css-ts-mode)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-derived-mode css-mode css-base-mode "CSS"
|
(define-derived-mode css-mode css-base-mode "CSS"
|
||||||
"Major mode to edit Cascading Style Sheets (CSS).
|
"Major mode to edit Cascading Style Sheets (CSS).
|
||||||
|
|
|
||||||
|
|
@ -186,8 +186,8 @@ Return nil if there is no name or if NODE is not a defun node."
|
||||||
|
|
||||||
(derived-mode-add-parents 'html-ts-mode '(html-mode))
|
(derived-mode-add-parents 'html-ts-mode '(html-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'html t)
|
;; No `auto-mode-alist' associations are defined here
|
||||||
(add-to-list 'auto-mode-alist '("\\.html\\'" . html-ts-mode)))
|
;; to give preference to `mhtml-ts-mode'.
|
||||||
|
|
||||||
(provide 'html-ts-mode)
|
(provide 'html-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -403,8 +403,21 @@ the same features enabled in MODE."
|
||||||
|
|
||||||
(derived-mode-add-parents 'markdown-ts-mode '(markdown-mode))
|
(derived-mode-add-parents 'markdown-ts-mode '(markdown-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'markdown)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode)))
|
(defun markdown-ts-mode-maybe ()
|
||||||
|
"Enable `markdown-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'markdown)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'markdown-ts-mode treesit-enabled-modes))
|
||||||
|
(markdown-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-ts-mode-maybe))
|
||||||
|
;; To be able to toggle between an external package and core ts-mode:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(markdown-mode . markdown-ts-mode)))
|
||||||
|
|
||||||
(provide 'markdown-ts-mode)
|
(provide 'markdown-ts-mode)
|
||||||
;;; markdown-ts-mode.el ends here
|
;;; markdown-ts-mode.el ends here
|
||||||
|
|
|
||||||
|
|
@ -587,9 +587,10 @@ Powered by tree-sitter."
|
||||||
;; Add some extra parents.
|
;; Add some extra parents.
|
||||||
(derived-mode-add-parents 'mhtml-ts-mode '(css-mode js-mode))
|
(derived-mode-add-parents 'mhtml-ts-mode '(css-mode js-mode))
|
||||||
|
|
||||||
(when (and (treesit-ready-p 'html t) (treesit-ready-p 'javascript t) (treesit-ready-p 'css t))
|
;;;###autoload
|
||||||
(add-to-list
|
(when (treesit-available-p)
|
||||||
'auto-mode-alist '("\\.[sx]?html?\\(\\.[a-zA-Z_]+\\)?\\'" . mhtml-ts-mode)))
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(mhtml-mode . mhtml-ts-mode)))
|
||||||
|
|
||||||
(provide 'mhtml-ts-mode)
|
(provide 'mhtml-ts-mode)
|
||||||
;;; mhtml-ts-mode.el ends here
|
;;; mhtml-ts-mode.el ends here
|
||||||
|
|
|
||||||
|
|
@ -172,8 +172,10 @@ 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))
|
||||||
|
|
||||||
(if (treesit-ready-p 'toml)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode)))
|
(when (treesit-available-p)
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(conf-toml-mode . toml-ts-mode)))
|
||||||
|
|
||||||
(provide 'toml-ts-mode)
|
(provide 'toml-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -227,8 +227,21 @@ Return nil if there is no name or if NODE is not a defun node."
|
||||||
|
|
||||||
(derived-mode-add-parents 'yaml-ts-mode '(yaml-mode))
|
(derived-mode-add-parents 'yaml-ts-mode '(yaml-mode))
|
||||||
|
|
||||||
(if (treesit-ready-p 'yaml)
|
;;;###autoload
|
||||||
(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode)))
|
(defun yaml-ts-mode-maybe ()
|
||||||
|
"Enable `yaml-ts-mode' when its grammar is available."
|
||||||
|
(if (or (treesit-language-available-p 'yaml)
|
||||||
|
(eq treesit-enabled-modes t)
|
||||||
|
(memq 'yaml-ts-mode treesit-enabled-modes))
|
||||||
|
(yaml-ts-mode)
|
||||||
|
(fundamental-mode)))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(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:
|
||||||
|
(add-to-list 'treesit-major-mode-remap-alist
|
||||||
|
'(yaml-mode . yaml-ts-mode)))
|
||||||
|
|
||||||
(provide 'yaml-ts-mode)
|
(provide 'yaml-ts-mode)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,8 @@ in a Emacs not built with tree-sitter library."
|
||||||
|
|
||||||
(declare-function treesit-available-p "treesit.c")
|
(declare-function treesit-available-p "treesit.c")
|
||||||
|
|
||||||
(defvar treesit-thing-settings)))
|
(defvar treesit-thing-settings)
|
||||||
|
(defvar treesit-major-mode-remap-alist)))
|
||||||
|
|
||||||
(treesit-declare-unavailable-functions)
|
(treesit-declare-unavailable-functions)
|
||||||
|
|
||||||
|
|
@ -5399,6 +5400,31 @@ Tree-sitter grammar for `%s' is missing; install it?"
|
||||||
;; Check that the grammar was installed successfully
|
;; Check that the grammar was installed successfully
|
||||||
(treesit-ready-p lang)))))
|
(treesit-ready-p lang)))))
|
||||||
|
|
||||||
|
;;; Treesit enabled modes
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defcustom treesit-enabled-modes nil
|
||||||
|
"Specify what treesit modes to enable by default.
|
||||||
|
The value can be either a list of ts-modes to enable,
|
||||||
|
or t to enable all ts-modes."
|
||||||
|
:type `(choice
|
||||||
|
(const :tag "Disable all automatic associations" nil)
|
||||||
|
(const :tag "Enable all available ts-modes" t)
|
||||||
|
(set :tag "List of enabled ts-modes"
|
||||||
|
,@(when (treesit-available-p)
|
||||||
|
(sort (mapcar (lambda (m) `(function-item ,m))
|
||||||
|
(seq-uniq (mapcar #'cdr treesit-major-mode-remap-alist)))))))
|
||||||
|
:initialize #'custom-initialize-default
|
||||||
|
:set (lambda (sym val)
|
||||||
|
(set-default sym val)
|
||||||
|
(when (treesit-available-p)
|
||||||
|
(dolist (m treesit-major-mode-remap-alist)
|
||||||
|
(setq major-mode-remap-alist
|
||||||
|
(if (or (eq val t) (memq (cdr m) val))
|
||||||
|
(cons m major-mode-remap-alist)
|
||||||
|
(delete m major-mode-remap-alist))))))
|
||||||
|
:version "31.1")
|
||||||
|
|
||||||
;;; Shortdocs
|
;;; Shortdocs
|
||||||
|
|
||||||
(defun treesit--generate-shortdoc-examples ()
|
(defun treesit--generate-shortdoc-examples ()
|
||||||
|
|
|
||||||
|
|
@ -5299,6 +5299,16 @@ language is in this list, Emacs enables line-column tracking for the
|
||||||
buffer. */);
|
buffer. */);
|
||||||
Vtreesit_languages_require_line_column_tracking = Qnil;
|
Vtreesit_languages_require_line_column_tracking = Qnil;
|
||||||
|
|
||||||
|
DEFVAR_LISP ("treesit-major-mode-remap-alist",
|
||||||
|
Vtreesit_major_mode_remap_alist,
|
||||||
|
doc:
|
||||||
|
/* Alist mapping file-specified modes to ts-modes.
|
||||||
|
|
||||||
|
The value should be an alist of (MODE . TS-MODE).
|
||||||
|
This alist is used to modify the value of `major-mode-remap-alist'
|
||||||
|
depending on customization of `treesit-enabled-modes'. */);
|
||||||
|
Vtreesit_major_mode_remap_alist = Qnil;
|
||||||
|
|
||||||
staticpro (&Vtreesit_str_libtree_sitter);
|
staticpro (&Vtreesit_str_libtree_sitter);
|
||||||
Vtreesit_str_libtree_sitter = build_string ("libtree-sitter-");
|
Vtreesit_str_libtree_sitter = build_string ("libtree-sitter-");
|
||||||
staticpro (&Vtreesit_str_tree_sitter);
|
staticpro (&Vtreesit_str_tree_sitter);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue