]> git.eshelyaron.com Git - emacs.git/commitdiff
Add non-TS modes as extra parent of TS modes (bug#68246)
authorStefan Monnier <monnier@iro.umontreal.ca>
Fri, 8 Mar 2024 17:58:11 +0000 (12:58 -0500)
committerEshel Yaron <me@eshelyaron.com>
Mon, 11 Mar 2024 09:23:43 +0000 (10:23 +0100)
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)

22 files changed:
etc/NEWS
lisp/progmodes/c-ts-mode.el
lisp/progmodes/cmake-ts-mode.el
lisp/progmodes/cperl-mode.el
lisp/progmodes/csharp-mode.el
lisp/progmodes/dockerfile-ts-mode.el
lisp/progmodes/elixir-ts-mode.el
lisp/progmodes/go-ts-mode.el
lisp/progmodes/heex-ts-mode.el
lisp/progmodes/java-ts-mode.el
lisp/progmodes/js.el
lisp/progmodes/json-ts-mode.el
lisp/progmodes/lua-ts-mode.el
lisp/progmodes/python.el
lisp/progmodes/ruby-ts-mode.el
lisp/progmodes/rust-ts-mode.el
lisp/progmodes/sh-script.el
lisp/progmodes/typescript-ts-mode.el
lisp/textmodes/css-mode.el
lisp/textmodes/html-ts-mode.el
lisp/textmodes/toml-ts-mode.el
lisp/textmodes/yaml-ts-mode.el

index e81fff8cd8fc67d722a1e6fccb7f6620048ad7a6..e78e5c848e48e210cf7da7985a246e5636855691 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -68,6 +68,16 @@ more details.
 \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
index 38b72e59388fc96ef993e1828986f8d8128f4980..a2e7f6fba2e54deb1ac17a73147916b0fd5bbc73 100644 (file)
@@ -1328,6 +1328,8 @@ in your configuration."
                   (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.
@@ -1371,6 +1373,8 @@ recommended to enable `electric-pair-mode' with this mode."
       (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++"
index 45c4882d8737d51d1dd8afb2ae77ee281e133e55..b70806f4c30e67a00a3032029b5a88be222ab261 100644 (file)
@@ -243,6 +243,8 @@ Return nil if there is no name or if NODE is not a defun node."
 
     (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)))
index 10ac80dffd57d18c63538f4f22771c12499e3e84..11709bfe00b7f082694aff9384c65a2617645b20 100644 (file)
@@ -1934,6 +1934,8 @@ or as help on variables `cperl-tips', `cperl-problems',
   ;; 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)))
index 7bf57bcbe21ab3468e418caf0a7e489cc63ef688..18114d08528e0bd1853b06e0857107a57843d168 100644 (file)
@@ -998,6 +998,8 @@ Key bindings:
 
   (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
index f658701851387ff56ecfd1d8d77bb08842cd8f59..e31fd86bbdf40bd6e644110af14ed686513ae4d7 100644 (file)
@@ -165,6 +165,8 @@ Return nil if there is no name or if NODE is not a stage node."
 
     (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.
index f26c3a49203da0e25265a1d19af017ab88608722..9804152d9abd508ce366c6eec2599cbf44d085bd 100644 (file)
@@ -753,6 +753,8 @@ Return nil if NODE is not a defun node or doesn't have a name."
     (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))
index 296e4d0037df5b74284cecf87ae8e1a05c67d202..cc330688dc372dea26bada55a908a44d59766442 100644 (file)
 
     (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'?
@@ -439,6 +441,8 @@ what the parent of the node would be if it were a node."
 
     (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)))
 
index 22e8956661dda36b57474c4d5c645b2c4c9b82ee..07b8bfdc74f2ac12d087695e8bc9f8dbc05024e8 100644 (file)
@@ -187,6 +187,8 @@ With ARG, do it many times.  Negative ARG means move backward."
 
     (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.
index 00d7d0d75a1039fa53cbd21cebec305d74692277..bb4a7df3340e53a6320bf877ef6bc23c3c1552a0 100644 (file)
@@ -406,6 +406,8 @@ Return nil if there is no name or if NODE is not a defun node."
                 ("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)))
 
index ebc098e6a75559e6004026b92c70f39d5fe79912..6cb84592896734b9013aee03b4ed66a9d3dd32e8 100644 (file)
@@ -3916,6 +3916,8 @@ See `treesit-thing-settings' for more information.")
     (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
index 32bc10bbda9fd616f1fa49ae5de435de4e4fcad7..1fb96555010514c361c9e255ff90a7f9e4b7ca11 100644 (file)
@@ -164,6 +164,8 @@ Return nil if there is no name or if NODE is not a defun node."
 
   (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)))
index 8bd3db2b75f181ae6f3764cbf651c912f465d448..25fd7792f4248785799fb705494bd476faec4fd1 100644 (file)
@@ -798,6 +798,8 @@ Calls REPORT-FN directly."
 
   (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)))
 
index bedc61408ef1bcd4d12e565790a2b59d1f740271..1016655cb62a6e77095b27e7f2d8f716f7e189c1 100644 (file)
@@ -7128,6 +7128,8 @@ implementations: `python-mode' and `python-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
index aa6c5b1b6cc41dbc8eb2ca96c1d92f8a8521336d..7133cb0b5b0a1e4c634975d04612d6fa717fa3e3 100644 (file)
@@ -1210,14 +1210,7 @@ leading double colon is not added."
 
   (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
index c5fc57cc374f9280865799b72098e82708343bdd..c67ac43e4d09adc933c228cf85b65a6753f4ee89 100644 (file)
@@ -474,6 +474,8 @@ See `prettify-symbols-compose-predicate'."
 
     (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)))
 
index 43fb8a723bd00fb6a162cec91beed91daf56818c..ab95dc9f92459736ecb13e1f7c31584658bb9c92 100644 (file)
@@ -1639,6 +1639,8 @@ not written in Bash or sh."
     (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.
index 9ee9432e4eec1eef691dd18ffa3e432786311fba..ea4f6417c5a8c80154323b2e2c8a4c39a2bb6a82 100644 (file)
@@ -505,6 +505,8 @@ This mode is intended to be inherited by concrete major modes."
 
     (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)))
 
@@ -562,6 +564,8 @@ at least 3 (which is the default value)."
 
     (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
index 425f3ec8a306ca2983fbfbe93d68f7095cf9e948..f5a20e0ca0e8bf156d20671a0b8148f957b28cba 100644 (file)
@@ -1830,6 +1830,8 @@ can also be used to fill comments.
 
     (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).
index 9af2aa6748f919baf045add1646014481c2b939f..235e1055fa956d81c305522d9f4b8b4fb512408b 100644 (file)
@@ -134,6 +134,8 @@ Return nil if there is no name or if NODE is not a defun node."
 
   (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)))
 
index 1ba410045f5d5bbdfd4fd8b2c99cf5f53174044f..1b621032f8ae90c6b6cb3f6f3d02b5d7566df735 100644 (file)
@@ -153,6 +153,8 @@ Return nil if there is no name or if NODE is not a defun node."
 
     (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)))
 
index a8cb504ef03c4aab0e7cc74e4ec1bfe667a90712..210835585feeb2f685d0eb7ffd505aeb10ddd35e 100644 (file)
@@ -169,6 +169,8 @@ boundaries.  JUSTIFY is passed to `fill-paragraph'."
 
     (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)))