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'.
This commit is contained in:
Juri Linkov 2025-03-02 20:44:40 +02:00
parent a5e82110b0
commit 888a2b5394
2 changed files with 37 additions and 30 deletions

View 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)

View 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)