From 25c4a469e420fd9ca44d3db5211bce9893ee754b Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 4 May 2025 20:50:40 +0300 Subject: [PATCH] Avoid duplication in defining tree-sitter grammar sources. * 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 | 21 ++++++--------------- lisp/textmodes/mhtml-ts-mode.el | 23 +++++------------------ test/infra/Dockerfile.emba | 6 +++--- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el index c13b31a439a..46217473fe6 100644 --- a/lisp/progmodes/php-ts-mode.el +++ b/lisp/progmodes/php-ts-mode.el @@ -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) @@ -82,11 +83,7 @@ ;;; 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) diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el index 5a29c9f0ee5..6285d730efb 100644 --- a/lisp/textmodes/mhtml-ts-mode.el +++ b/lisp/textmodes/mhtml-ts-mode.el @@ -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)) @@ -62,26 +62,13 @@ ;; 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 diff --git a/test/infra/Dockerfile.emba b/test/infra/Dockerfile.emba index c6aed2aeac9..b7af7006acf 100644 --- a/test/infra/Dockerfile.emba +++ b/test/infra/Dockerfile.emba @@ -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" \ -- 2.39.5