Record the fact that TS modes are alternatives to the non-TS
modes using the new `derived-mode-add-parents` functionality.
Do the same for long standing similar issues with CPerl-mode.
* lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode):
* lisp/textmodes/toml-ts-mode.el (toml-ts-mode):
* lisp/textmodes/html-ts-mode.el (html-ts-mode):
* lisp/textmodes/css-mode.el (css-ts-mode):
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode, tsx-ts-mode):
* lisp/progmodes/sh-script.el (bash-ts-mode):
* lisp/progmodes/rust-ts-mode.el (rust-ts-mode):
* lisp/progmodes/ruby-ts-mode.el (ruby-ts-mode):
* lisp/progmodes/python.el (python-ts-mode):
* lisp/progmodes/lua-ts-mode.el (lua-ts-mode):
* lisp/progmodes/json-ts-mode.el (json-ts-mode):
* lisp/progmodes/js.el (js-ts-mode):
* lisp/progmodes/java-ts-mode.el (java-ts-mode):
* lisp/progmodes/heex-ts-mode.el (heex-ts-mode):
* lisp/progmodes/go-ts-mode.el (go-ts-mode, go-mod-ts-mode):
* lisp/progmodes/elixir-ts-mode.el (elixir-ts-mode):
* lisp/progmodes/dockerfile-ts-mode.el (dockerfile-ts-mode):
* lisp/progmodes/csharp-mode.el (csharp-ts-mode):
* lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode):
* lisp/progmodes/c-ts-mode.el (c-ts-mode, c++-ts-mode):
Add non-TS mode as extra parent.
* lisp/progmodes/cperl-mode.el (cperl-mode): Add `perl-mode` as
extra parent.
(cherry picked from commit
c79a509384d33dab6a964ef9a97cbc9a1f1b5bf7)
\f
* Incompatible Changes in Emacs 30.1
+** Tree-Sitter modes are now declared as submodes of the non-TS modes.
+In order to help the use of those Tree-Sitter modes, they are now
+declared to have the corresponding non-Tree-Sitter mode as an
+additional parent.
+This way, things like `.dir-locals.el` settings, and YASnippet
+collections of snippets automatically apply to the new Tree-Sitter modes.
+
+Note that those modes still do not inherit from the non-TS mode, so
+configuration settings installed via mode hooks are not affected.
+
+++
** URL now never sends user email addresses in HTTP requests.
Emacs never sent email addresses by default, but it used to be
(lambda (_pos) 'c))
(treesit-font-lock-recompute-features '(emacs-devel)))))
+(derived-mode-add-parents 'c-ts-mode '(c-mode))
+
;;;###autoload
(define-derived-mode c++-ts-mode c-ts-base-mode "C++"
"Major mode for editing C++, powered by tree-sitter.
(setq-local add-log-current-defun-function
#'c-ts-mode--emacs-current-defun-name))))
+(derived-mode-add-parents 'c++-ts-mode '(c++-mode))
+
(easy-menu-define c-ts-mode-menu (list c-ts-mode-map c++-ts-mode-map)
"Menu for `c-ts-mode' and `c++-ts-mode'."
'("C/C++"
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'cmake-ts-mode '(cmake-mode))
+
(if (treesit-ready-p 'cmake)
(add-to-list 'auto-mode-alist
'("\\(?:CMakeLists\\.txt\\|\\.cmake\\)\\'" . cmake-ts-mode)))
;; Setup Flymake
(add-hook 'flymake-diagnostic-functions #'perl-flymake nil t))
+(derived-mode-add-parents 'cperl-mode '(perl-mode))
+
(defun cperl--set-file-style ()
(when cperl-file-style
(cperl-file-style cperl-file-style)))
(add-to-list 'auto-mode-alist '("\\.cs\\'" . csharp-ts-mode)))
+(derived-mode-add-parents 'csharp-ts-mode '(csharp-mode))
+
(provide 'csharp-mode)
;;; csharp-mode.el ends here
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'dockerfile-ts-mode '(dockerfile-mode))
+
(if (treesit-ready-p 'dockerfile)
(add-to-list 'auto-mode-alist
;; NOTE: We can't use `rx' here, as it breaks bootstrap.
(treesit-major-mode-setup)
(setq-local syntax-propertize-function #'elixir-ts--syntax-propertize)))
+(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))
(treesit-major-mode-setup)))
+(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'?
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'go-mod-ts-mode '(go-mod-mode))
+
(if (treesit-ready-p 'gomod)
(add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode)))
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'heex-ts-mode '(heex-mode))
+
(if (treesit-ready-p 'heex)
;; Both .heex and the deprecated .leex files should work
;; with the tree-sitter-heex grammar.
("Method" "\\`method_declaration\\'" nil nil)))
(treesit-major-mode-setup))
+(derived-mode-add-parents 'java-ts-mode '(java-mode))
+
(if (treesit-ready-p 'java)
(add-to-list 'auto-mode-alist '("\\.java\\'" . java-ts-mode)))
(add-to-list 'auto-mode-alist
'("\\(\\.js[mx]\\|\\.har\\)\\'" . js-ts-mode))))
+(derived-mode-add-parents 'js-ts-mode '(js-mode))
+
(defvar js-ts--s-p-query
(when (treesit-available-p)
(treesit-query-compile 'javascript
(treesit-major-mode-setup))
+(derived-mode-add-parents 'json-ts-mode '(json-mode))
+
(if (treesit-ready-p 'json)
(add-to-list 'auto-mode-alist
'("\\.json\\'" . json-ts-mode)))
(add-hook 'flymake-diagnostic-functions #'lua-ts-flymake-luacheck nil 'local))
+(derived-mode-add-parents 'lua-ts-mode '(lua-mode))
+
(when (treesit-ready-p 'lua)
(add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-ts-mode)))
(add-to-list 'auto-mode-alist '("\\.py[iw]?\\'" . python-ts-mode))
(add-to-list 'interpreter-mode-alist '("python[0-9.]*" . python-ts-mode))))
+(derived-mode-add-parents 'python-ts-mode '(python-mode))
+
;;; Completion predicates for M-x
;; Commands that only make sense when editing Python code.
(dolist (sym '(python-add-import
(setq-local syntax-propertize-function #'ruby-ts--syntax-propertize))
-(defun ruby-ts--parser-after-change (ranges parser)
- ;; Make sure we re-syntax-propertize the full node that is being
- ;; edited. This is most pertinent to multi-line complex nodes such
- ;; as heredocs.
- (when ranges
- (with-current-buffer (treesit-parser-buffer parser)
- (syntax-ppss-flush-cache (cl-loop for r in ranges
- minimize (car r))))))
+(derived-mode-add-parents 'ruby-ts-mode '(ruby-mode))
(if (treesit-ready-p 'ruby)
(add-to-list 'major-mode-remap-defaults
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'rust-ts-mode '(rust-mode))
+
(if (treesit-ready-p 'rust)
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-ts-mode)))
(setq-local treesit-defun-type-regexp "function_definition")
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'bash-ts-mode '(sh-mode))
+
(advice-add 'bash-ts-mode :around #'sh--redirect-bash-ts-mode
;; Give it lower precedence than normal advice, so other
;; advices take precedence over it.
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'typescript-ts-mode '(typescript-mode))
+
(if (treesit-ready-p 'typescript)
(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-ts-mode)))
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'tsx-ts-mode '(tsx-mode))
+
(defvar typescript-ts--s-p-query
(when (treesit-available-p)
(treesit-query-compile 'typescript
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-ts-mode))))
+(derived-mode-add-parents 'css-ts-mode '(css-mode))
+
;;;###autoload
(define-derived-mode css-mode css-base-mode "CSS"
"Major mode to edit Cascading Style Sheets (CSS).
(treesit-major-mode-setup))
+(derived-mode-add-parents 'html-ts-mode '(html-mode))
+
(if (treesit-ready-p 'html)
(add-to-list 'auto-mode-alist '("\\.html\\'" . html-ts-mode)))
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'toml-ts-mode '(toml-mode))
+
(if (treesit-ready-p 'toml)
(add-to-list 'auto-mode-alist '("\\.toml\\'" . toml-ts-mode)))
(treesit-major-mode-setup)))
+(derived-mode-add-parents 'yaml-ts-mode '(yaml-mode))
+
(if (treesit-ready-p 'yaml)
(add-to-list 'auto-mode-alist '("\\.ya?ml\\'" . yaml-ts-mode)))