]> git.eshelyaron.com Git - emacs.git/commitdiff
Set treesit-primary-parser for tree-sitter modes
authorYuan Fu <casouri@gmail.com>
Tue, 8 Oct 2024 00:24:32 +0000 (17:24 -0700)
committerEshel Yaron <me@eshelyaron.com>
Tue, 15 Oct 2024 19:43:21 +0000 (21:43 +0200)
I debated whether to do this, since technically speaking it's
not needed for single-language modes.  But ultimately it's
better to be explicit and set a good example with builtin modes.

* lisp/progmodes/cmake-ts-mode.el (cmake-ts-mode):
* lisp/progmodes/csharp-mode.el (csharp-ts-mode):
* lisp/progmodes/dockerfile-ts-mode.el (dockerfile-ts-mode):
* lisp/progmodes/go-ts-mode.el (go-ts-mode):
(go-mod-ts-mode):
* lisp/progmodes/heex-ts-mode.el (heex-ts-mode):
* lisp/progmodes/json-ts-mode.el (json-ts-mode):
* lisp/progmodes/lua-ts-mode.el (lua-ts-mode):
* lisp/progmodes/python.el (python-ts-mode):
* lisp/progmodes/ruby-ts-mode.el (ruby-ts-mode):
* lisp/progmodes/rust-ts-mode.el (rust-ts-mode):
* lisp/progmodes/sh-script.el:
* lisp/progmodes/typescript-ts-mode.el (typescript-ts-mode):
(tsx-ts-mode):
* lisp/textmodes/css-mode.el (css-ts-mode):
* lisp/textmodes/html-ts-mode.el (html-ts-mode):
* lisp/textmodes/toml-ts-mode.el (toml-ts-mode):
* lisp/textmodes/yaml-ts-mode.el (yaml-ts-mode): Set
treesit-primary-parser.

(cherry picked from commit c436d4eff97b3919c9f8cdec504272d6f7ed393f)

16 files changed:
lisp/progmodes/cmake-ts-mode.el
lisp/progmodes/csharp-mode.el
lisp/progmodes/dockerfile-ts-mode.el
lisp/progmodes/go-ts-mode.el
lisp/progmodes/heex-ts-mode.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 854adf4ade7e4415886a67437d00a5e028b78efc..597ef69d9b87fc1fb22ef3f6f4babcdb5e08adaa 100644 (file)
@@ -208,7 +208,7 @@ Return nil if there is no name or if NODE is not a defun node."
   :syntax-table cmake-ts-mode--syntax-table
 
   (when (treesit-ready-p 'cmake)
-    (treesit-parser-create 'cmake)
+    (setq treesit-primary-parser (treesit-parser-create 'cmake))
 
     ;; Comments.
     (setq-local comment-start "# ")
index 1f86527191a1798710e5ab7b7ab454986b4d2391..b86555b1d878c88409afa91df1b793eaa5f752c7 100644 (file)
@@ -1049,7 +1049,7 @@ Key bindings:
     (error "Tree-sitter for C# isn't available"))
 
   ;; Tree-sitter.
-  (treesit-parser-create 'c-sharp)
+  (setq treesit-primary-parser (treesit-parser-create 'c-sharp))
 
   ;; Comments.
   (c-ts-common-comment-setup)
index e31fd86bbdf40bd6e644110af14ed686513ae4d7..42fa7482a87c356092ebf525cad45a1ffe0aa037 100644 (file)
@@ -133,7 +133,7 @@ Return nil if there is no name or if NODE is not a stage node."
   :syntax-table dockerfile-ts-mode--syntax-table
 
   (when (treesit-ready-p 'dockerfile)
-    (treesit-parser-create 'dockerfile)
+    (setq treesit-primary-parser (treesit-parser-create 'dockerfile))
 
     ;; Comments.
     (setq-local comment-start "# ")
index cb9a58e33b54105c01eeedd9026729949b1e3da0..6fa8049e5e7e01cf85bf10785523497f4cd5edb4 100644 (file)
   :syntax-table go-ts-mode--syntax-table
 
   (when (treesit-ready-p 'go)
-    (treesit-parser-create 'go)
+    (setq treesit-primary-parser (treesit-parser-create 'go))
 
     ;; Comments.
     (setq-local comment-start "// ")
@@ -539,7 +539,7 @@ what the parent of the node would be if it were a node."
   :syntax-table go-mod-ts-mode--syntax-table
 
   (when (treesit-ready-p 'gomod)
-    (treesit-parser-create 'gomod)
+    (setq treesit-primary-parser (treesit-parser-create 'gomod))
 
     ;; Comments.
     (setq-local comment-start "// ")
index b527d96b5794a35b6c27de4d5b82d08aff77665e..84fd513525c4f98f77f7ee996378bf54e168bbd7 100644 (file)
@@ -148,7 +148,7 @@ With ARG, do it many times.  Negative ARG means move backward."
   :group 'heex-ts
 
   (when (treesit-ready-p 'heex)
-    (treesit-parser-create 'heex)
+    (setq treesit-primary-parser (treesit-parser-create 'heex))
 
     ;; Comments
     (setq-local treesit-thing-settings
index 1fb96555010514c361c9e255ff90a7f9e4b7ca11..7409c6be833b74649cec95859c48c7a69225e1f4 100644 (file)
@@ -128,7 +128,7 @@ Return nil if there is no name or if NODE is not a defun node."
   (unless (treesit-ready-p 'json)
     (error "Tree-sitter for JSON isn't available"))
 
-  (treesit-parser-create 'json)
+  (setq treesit-primary-parser (treesit-parser-create 'json))
 
   ;; Comments.
   (setq-local comment-start "// ")
index a1dae0628d40c399294f06d70856fc048c3c2022..20bc1f3e158a4b0f22de575a67319cc85f39ea29 100644 (file)
@@ -750,7 +750,7 @@ Calls REPORT-FN directly."
   (use-local-map lua-ts-mode-map)
 
   (when (treesit-ready-p 'lua)
-    (treesit-parser-create 'lua)
+    (setq treesit-primary-parser (treesit-parser-create 'lua))
 
     ;; Comments.
     (setq-local comment-start "--")
index 63064ff4de902501233c48c2b215f789816f1cb5..18baf136f576ca19e2cec65f640bb92f1c04e76e 100644 (file)
@@ -7161,7 +7161,7 @@ implementations: `python-mode' and `python-ts-mode'."
 \\{python-ts-mode-map}"
   :syntax-table python-mode-syntax-table
   (when (treesit-ready-p 'python)
-    (treesit-parser-create 'python)
+    (setq treesit-primary-parser (treesit-parser-create 'python))
     (setq-local treesit-font-lock-feature-list
                 '(( comment definition)
                   ( keyword string type)
index adcdf15c7ad7fdfaacbdee28d8d28373210bbc0b..aff0b8911b9a20c1d1e21c30d1c36ff6da8fc699 100644 (file)
@@ -1127,7 +1127,7 @@ leading double colon is not added."
   (unless (treesit-ready-p 'ruby)
     (error "Tree-sitter for Ruby isn't available"))
 
-  (treesit-parser-create 'ruby)
+  (setq treesit-primary-parser (treesit-parser-create 'ruby))
 
   (setq-local add-log-current-defun-function #'ruby-ts-add-log-current-function)
 
index b7a52b06b244bb5b376dc22f5b8f087bc19ddd88..e52ea3b125a7fd2b36d8ea8b135e1c1570428972 100644 (file)
@@ -511,7 +511,7 @@ See `prettify-symbols-compose-predicate'."
   :syntax-table rust-ts-mode--syntax-table
 
   (when (treesit-ready-p 'rust)
-    (treesit-parser-create 'rust)
+    (setq treesit-primary-parser (treesit-parser-create 'rust))
 
     ;; Syntax.
     (setq-local syntax-propertize-function
index fccee14af822e49f2a3073dfc3e23a647757afca..f817e55a04c0c9387cd0f79e4b3197f817eaeace 100644 (file)
@@ -1623,7 +1623,7 @@ not written in Bash or sh."
     (add-hook 'flymake-diagnostic-functions #'sh-shellcheck-flymake nil t)
     (add-hook 'hack-local-variables-hook
               #'sh-after-hack-local-variables nil t)
-    (treesit-parser-create 'bash)
+    (setq treesit-primary-parser (treesit-parser-create 'bash))
     (setq-local treesit-font-lock-feature-list
                 '(( comment function)
                   ( command declaration-command keyword string)
index 1c0f3f2790ec9a2aeacc6b205cdac1ae42ae677f..f3c60e5c0e7b23524d133e38910c4407ab6c3641 100644 (file)
@@ -513,7 +513,7 @@ This mode is intended to be inherited by concrete major modes."
   :syntax-table typescript-ts-mode--syntax-table
 
   (when (treesit-ready-p 'typescript)
-    (treesit-parser-create 'typescript)
+    (setq treesit-primary-parser (treesit-parser-create 'typescript))
 
     ;; Indent.
     (setq-local treesit-simple-indent-rules
@@ -551,7 +551,7 @@ at least 3 (which is the default value)."
   :syntax-table typescript-ts-mode--syntax-table
 
   (when (treesit-ready-p 'tsx)
-    (treesit-parser-create 'tsx)
+    (setq treesit-primary-parser (treesit-parser-create 'tsx))
 
     ;; Comments.
     (setq-local comment-start "// ")
index af2accb87340c558a452b065496fef4c89aaed22..5abe8fc30d8f0714f9836763bf622a9d4cd2c475 100644 (file)
@@ -1814,7 +1814,7 @@ can also be used to fill comments.
     (setq-local font-lock-fontify-region-function #'css--fontify-region)
 
     ;; Tree-sitter specific setup.
-    (treesit-parser-create 'css)
+    (setq treesit-primary-parser (treesit-parser-create 'css))
     (setq-local treesit-simple-indent-rules css--treesit-indent-rules)
     (setq-local treesit-defun-type-regexp "rule_set")
     (setq-local treesit-defun-name-function #'css--treesit-defun-name)
index 235e1055fa956d81c305522d9f4b8b4fb512408b..f78fbdde1da065152492f33e9fb284c721f4b9e3 100644 (file)
@@ -92,7 +92,7 @@ Return nil if there is no name or if NODE is not a defun node."
   (unless (treesit-ready-p 'html)
     (error "Tree-sitter for HTML isn't available"))
 
-  (treesit-parser-create 'html)
+  (setq treesit-primary-parser (treesit-parser-create 'html))
 
   ;; Indent.
   (setq-local treesit-simple-indent-rules html-ts-mode--indent-rules)
index 3c4533a7fea1c8cbf044afad56304ac6cf06a323..806f045c23baa6c79d776997a47c44a7cb1eb31b 100644 (file)
@@ -124,7 +124,7 @@ Return nil if there is no name or if NODE is not a defun node."
   :syntax-table toml-ts-mode--syntax-table
 
   (when (treesit-ready-p 'toml)
-    (treesit-parser-create 'toml)
+    (setq treesit-primary-parser (treesit-parser-create 'toml))
 
     ;; Comments
     (setq-local comment-start "# ")
index 210835585feeb2f685d0eb7ffd505aeb10ddd35e..42d7c2e1798465df26395ba0b2b15df3abc5c6e7 100644 (file)
@@ -148,7 +148,7 @@ boundaries.  JUSTIFY is passed to `fill-paragraph'."
   :syntax-table yaml-ts-mode--syntax-table
 
   (when (treesit-ready-p 'yaml)
-    (treesit-parser-create 'yaml)
+    (setq treesit-primary-parser (treesit-parser-create 'yaml))
 
     ;; Comments.
     (setq-local comment-start "# ")