]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid duplication in defining tree-sitter grammar sources.
authorJuri Linkov <juri@linkov.net>
Sun, 4 May 2025 17:50:40 +0000 (20:50 +0300)
committerEshel Yaron <me@eshelyaron.com>
Sat, 10 May 2025 08:49:42 +0000 (10:49 +0200)
* lisp/progmodes/php-ts-mode.el: Require 'html-ts-mode'.
(php-ts-mode--language-source-alist): Remove duplicate source info
for html, css, javascript, jsdoc.
(php-ts-mode-install-parsers): Install pre-defined grammars.
(php-ts-mode): Move 'require' to the top.

* lisp/textmodes/mhtml-ts-mode.el
(mhtml-ts-mode--language-source-alist): Remove variable
since 'treesit-language-source-alist' is pre-filled by
requiring 'html-ts-mode', 'css-mode', 'js'.
(mhtml-ts-mode-install-parsers): Install pre-defined grammars.

* test/infra/Dockerfile.emba: Remove 'mhtml-ts-mode'
that doesn't define own grammars.

(cherry picked from commit 815dea7b59392d83ca8f9e98d1569484aea605ad)

lisp/progmodes/php-ts-mode.el
lisp/textmodes/mhtml-ts-mode.el
test/infra/Dockerfile.emba

index c13b31a439a0cd5f67bbb4e6450364a91eb4d375..46217473fe6d5bf099d05ee8adab498761695948 100644 (file)
@@ -69,6 +69,7 @@
 
 (require 'treesit)
 (require 'c-ts-common) ;; For comment indent and filling.
+(require 'html-ts-mode) ;; for embed html
 (require 'css-mode) ;; for embed css into html
 (require 'js) ;; for embed javascript into html
 (require 'comint)
 ;;; Install treesitter language parsers
 (defvar php-ts-mode--language-source-alist
   '((php "https://github.com/tree-sitter/tree-sitter-php" "v0.23.11" "php/src")
-    (phpdoc "https://github.com/claytonrcarter/tree-sitter-phpdoc")
-    (html "https://github.com/tree-sitter/tree-sitter-html" "v0.23.2")
-    (javascript "https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.1")
-    (jsdoc "https://github.com/tree-sitter/tree-sitter-jsdoc" "v0.23.2")
-    (css "https://github.com/tree-sitter/tree-sitter-css" "v0.23.1"))
+    (phpdoc "https://github.com/claytonrcarter/tree-sitter-phpdoc"))
   "Treesitter language parsers required by `php-ts-mode'.
 You can customize `treesit-language-source-alist' if you want
 to stick to a specific commit and/or use different parsers.")
@@ -96,10 +93,11 @@ to stick to a specific commit and/or use different parsers.")
 
 (defun php-ts-mode-install-parsers ()
   "Install all the required treesitter parsers.
-`php-ts-mode--language-source-alist' defines which parsers to install."
+`treesit-language-source-alist' defines which parsers to install.
+It's pre-filled by loading \"html-ts-mode\", \"css-mode\", \"js\"."
   (interactive)
-  (dolist (item php-ts-mode--language-source-alist)
-    (treesit-install-language-grammar (car item))))
+  (dolist (lang '(php phpdoc html css javascript jsdoc))
+    (treesit-install-language-grammar lang)))
 
 ;;; Custom variables
 
@@ -1390,13 +1388,6 @@ Depends on `c-ts-common-comment-setup'."
     available.  You can install the parsers with M-x
     `php-ts-mode-install-parsers'")
 
-    ;; Require html-ts-mode only when we load php-ts-mode
-    ;; so that we don't get a tree-sitter compilation warning for
-    ;; php-ts-mode.
-    (defvar html-ts-mode--indent-rules)
-    (require 'html-ts-mode)
-    ;; For embed html
-
     ;; phpdoc is a local parser, don't create a parser for it
     (treesit-parser-create 'html)
     (treesit-parser-create 'css)
index 5a29c9f0ee57abf4e2fb8ab676ac9500e228bac0..6285d730efb2cb79d8abccc3813997f992f493a3 100644 (file)
@@ -50,9 +50,9 @@
 ;;; Code:
 
 (require 'treesit)
+(require 'html-ts-mode)
 (require 'css-mode) ;; for embed css into html
 (require 'js) ;; for embed javascript into html
-(require 'html-ts-mode)
 
 (eval-when-compile
   (require 'rx))
 ;; in a Emacs not built with tree-sitter library.
 (treesit-declare-unavailable-functions)
 
-;; In a multi-language major mode can be useful to have an "installer" to
-;; simplify the installation of the grammars supported by the major-mode.
-(defvar mhtml-ts-mode--language-source-alist
-  '((html "https://github.com/tree-sitter/tree-sitter-html" "v0.23.2")
-    (javascript "https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.1")
-    (jsdoc "https://github.com/tree-sitter/tree-sitter-jsdoc" "v0.23.2")
-    (css "https://github.com/tree-sitter/tree-sitter-css" "v0.23.1"))
-  "Treesitter language parsers required by `mhtml-ts-mode'.
-You can customize `treesit-language-source-alist' if you want
-to stick to a specific commit and/or use different parsers.")
-
-(dolist (item mhtml-ts-mode--language-source-alist)
-  (add-to-list 'treesit-language-source-alist item t))
-
 (defun mhtml-ts-mode-install-parsers ()
   "Install all the required treesitter parsers.
-`mhtml-ts-mode--language-source-alist' defines which parsers to install."
+`treesit-language-source-alist' defines which parsers to install.
+It's pre-filled by loading \"html-ts-mode\", \"css-mode\", \"js\"."
   (interactive)
-  (dolist (item mhtml-ts-mode--language-source-alist)
-    (treesit-install-language-grammar (car item))))
+  (dolist (lang '(html css javascript jsdoc))
+    (treesit-install-language-grammar lang)))
 
 ;;; Custom variables
 
index c6aed2aeac902761fce8cc9a8cbfb8e0673b8593..b7af7006acff6330666ccf2b3d21c14dd07172a6 100644 (file)
@@ -132,9 +132,9 @@ RUN src/emacs -Q --batch \
     --eval '(setq treesit-extra-load-path (list "/root/.emacs.d/tree-sitter"))' \
     --eval '(dolist (feature (quote (c-ts-mode cmake-ts-mode csharp-mode \
         dockerfile-ts-mode elixir-ts-mode heex-ts-mode go-ts-mode java-ts-mode \
-        js json-ts-mode lua-ts-mode python ruby-ts-mode rust-ts-mode sh-script \
-        typescript-ts-mode css-mode html-ts-mode markdown-ts-mode toml-ts-mode \
-        yaml-ts-mode mhtml-ts-mode php-ts-mode treesit-x))) (require feature))' \
+        js json-ts-mode lua-ts-mode php-ts-mode python ruby-ts-mode rust-ts-mode \
+        sh-script typescript-ts-mode css-mode html-ts-mode markdown-ts-mode \
+        toml-ts-mode yaml-ts-mode treesit-x))) (require feature))' \
     --eval '(dolist (lang (mapcar (quote car) treesit-language-source-alist)) \
         (treesit-install-language-grammar lang "/root/.emacs.d/tree-sitter"))' \
     --eval '(message "treesit-language-source-alist\n%s" \