From b76cfaede504b20a8bc097efdc3ae98010ea0799 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Sun, 2 Mar 2025 20:44:40 +0200 Subject: [PATCH] Adapt recent css-ts-mode changes to mhtml-ts-mode * lisp/textmodes/css-mode.el (css--treesit-thing-settings): (css-ts-mode--outline-predicate): New variables. (css-ts-mode): Set treesit-outline-predicate. * lisp/textmodes/mhtml-ts-mode.el (mhtml-ts-mode--treesit-thing-settings): Use css--treesit-thing-settings and css--treesit-defun-type-regexp. (mhtml-ts-mode): Use 'css-ts-mode--outline-predicate' for 'treesit-aggregated-outline-predicate'. (cherry picked from commit 888a2b5394f4574edd5fe6e76bef91aab8111ebd) --- lisp/textmodes/css-mode.el | 60 ++++++++++++++++++--------------- lisp/textmodes/mhtml-ts-mode.el | 7 ++-- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 9a93a7c591f..9960211ac64 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1780,6 +1780,33 @@ rgb()/rgba()." (replace-regexp-in-string "[\n ]+" " " s))) res))))))) +(defvar css--treesit-thing-settings + `((css (list + ,(rx bos (or "keyframe_block_list" + "block" + "pseudo_class_arguments" + "pseudo_class_with_selector_arguments" + "pseudo_class_nth_child_arguments" + "pseudo_element_arguments" + "feature_query" + "parenthesized_query" + "selector_query" + "parenthesized_value" + "grid_value" + "arguments") + eos)) + (sentence + ,(rx bos (or "import_statement" + "charset_statement" + "namespace_statement" + "postcss_statement" + "at_rule" + "declaration") + eos)) + (text + ,(rx bos "comment" eos)))) + "Settings for `treesit-thing-settings'.") + (defvar css--treesit-font-lock-feature-list '((selector comment query keyword) (property constant string) @@ -1796,6 +1823,10 @@ rgb()/rgba()." nil nil)) "Settings for `treesit-simple-imenu'.") +(defvar css-ts-mode--outline-predicate + (nth 1 (car css--treesit-simple-imenu-settings)) + "Predicate for `treesit-outline-predicate'.") + (defvar css--treesit-defun-type-regexp (rx bos (or "rule_set" "keyframe_block") eos) "Settings for `treesit-defun-type-regexp'.") @@ -1859,33 +1890,8 @@ can also be used to fill comments. (setq-local treesit-font-lock-settings css--treesit-settings) (setq-local treesit-font-lock-feature-list css--treesit-font-lock-feature-list) (setq-local treesit-simple-imenu-settings css--treesit-simple-imenu-settings) - (setq-local treesit-thing-settings - `((css - (list - ,(rx bos (or "keyframe_block_list" - "block" - "pseudo_class_arguments" - "pseudo_class_with_selector_arguments" - "pseudo_class_nth_child_arguments" - "pseudo_element_arguments" - "feature_query" - "parenthesized_query" - "selector_query" - "parenthesized_value" - "grid_value" - "arguments") - eos)) - (sentence - ,(rx bos (or "import_statement" - "charset_statement" - "namespace_statement" - "postcss_statement" - "at_rule" - "declaration" - ) - eos)) - (text - ,(rx bos (or "comment") eos))))) + (setq-local treesit-outline-predicate css-ts-mode--outline-predicate) + (setq-local treesit-thing-settings css--treesit-thing-settings) (treesit-major-mode-setup) diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el index 09fbb4c1cad..4d538514f1c 100644 --- a/lisp/textmodes/mhtml-ts-mode.el +++ b/lisp/textmodes/mhtml-ts-mode.el @@ -313,8 +313,9 @@ NODE and PARENT are ignored." (car js--treesit-thing-settings) `((defun ,js--treesit-defun-type-regexp))) ;; CSS thing settings - `(css - (defun ,(regexp-opt (list css--treesit-defun-type-regexp))))) + (append + (car css--treesit-thing-settings) + `((defun ,css--treesit-defun-type-regexp)))) "Settings for `treesit-thing-settings'.") ;; We use a function instead of a variable, because @@ -585,7 +586,7 @@ Powered by tree-sitter." `((html . ,#'html-ts-mode--outline-predicate) ;; TODO: add a predicate like for html above (javascript . "\\`function_declaration\\'") - (css . "\\`rule_set\\'"))) + (css . ,css-ts-mode--outline-predicate))) (treesit-major-mode-setup) -- 2.39.5