]> git.eshelyaron.com Git - emacs.git/commitdiff
Adapt recent css-ts-mode changes to mhtml-ts-mode
authorJuri Linkov <juri@linkov.net>
Sun, 2 Mar 2025 18:44:40 +0000 (20:44 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Mar 2025 21:02:52 +0000 (22:02 +0100)
* 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
lisp/textmodes/mhtml-ts-mode.el

index 9a93a7c591f88f2996aa4f5785fdf10fa444e1e4..9960211ac646307c5f6749706dcd2bc2327031c2 100644 (file)
@@ -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)
 
index 09fbb4c1cad51e44627fb3e34b596e213983ed14..4d538514f1c91b48c037a343acc02fce29c20970 100644 (file)
@@ -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)