aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2025-03-02 20:44:40 +0200
committerJuri Linkov2025-03-02 20:44:40 +0200
commit888a2b5394f4574edd5fe6e76bef91aab8111ebd (patch)
tree0c0d2a8e8471e801ebc7fb25b18bf232b7455674
parenta5e82110b087f05d50a9d628e70009ce33c33bc2 (diff)
downloademacs-888a2b5394f4574edd5fe6e76bef91aab8111ebd.tar.gz
emacs-888a2b5394f4574edd5fe6e76bef91aab8111ebd.zip
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'.
-rw-r--r--lisp/textmodes/css-mode.el60
-rw-r--r--lisp/textmodes/mhtml-ts-mode.el7
2 files changed, 37 insertions, 30 deletions
diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index 7249531d6d0..9437170673e 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -1780,6 +1780,33 @@ rgb()/rgba()."
1780 (replace-regexp-in-string "[\n ]+" " " s))) 1780 (replace-regexp-in-string "[\n ]+" " " s)))
1781 res))))))) 1781 res)))))))
1782 1782
1783(defvar css--treesit-thing-settings
1784 `((css (list
1785 ,(rx bos (or "keyframe_block_list"
1786 "block"
1787 "pseudo_class_arguments"
1788 "pseudo_class_with_selector_arguments"
1789 "pseudo_class_nth_child_arguments"
1790 "pseudo_element_arguments"
1791 "feature_query"
1792 "parenthesized_query"
1793 "selector_query"
1794 "parenthesized_value"
1795 "grid_value"
1796 "arguments")
1797 eos))
1798 (sentence
1799 ,(rx bos (or "import_statement"
1800 "charset_statement"
1801 "namespace_statement"
1802 "postcss_statement"
1803 "at_rule"
1804 "declaration")
1805 eos))
1806 (text
1807 ,(rx bos "comment" eos))))
1808 "Settings for `treesit-thing-settings'.")
1809
1783(defvar css--treesit-font-lock-feature-list 1810(defvar css--treesit-font-lock-feature-list
1784 '((selector comment query keyword) 1811 '((selector comment query keyword)
1785 (property constant string) 1812 (property constant string)
@@ -1796,6 +1823,10 @@ rgb()/rgba()."
1796 nil nil)) 1823 nil nil))
1797 "Settings for `treesit-simple-imenu'.") 1824 "Settings for `treesit-simple-imenu'.")
1798 1825
1826(defvar css-ts-mode--outline-predicate
1827 (nth 1 (car css--treesit-simple-imenu-settings))
1828 "Predicate for `treesit-outline-predicate'.")
1829
1799(defvar css--treesit-defun-type-regexp 1830(defvar css--treesit-defun-type-regexp
1800 (rx bos (or "rule_set" "keyframe_block") eos) 1831 (rx bos (or "rule_set" "keyframe_block") eos)
1801 "Settings for `treesit-defun-type-regexp'.") 1832 "Settings for `treesit-defun-type-regexp'.")
@@ -1859,33 +1890,8 @@ can also be used to fill comments.
1859 (setq-local treesit-font-lock-settings css--treesit-settings) 1890 (setq-local treesit-font-lock-settings css--treesit-settings)
1860 (setq-local treesit-font-lock-feature-list css--treesit-font-lock-feature-list) 1891 (setq-local treesit-font-lock-feature-list css--treesit-font-lock-feature-list)
1861 (setq-local treesit-simple-imenu-settings css--treesit-simple-imenu-settings) 1892 (setq-local treesit-simple-imenu-settings css--treesit-simple-imenu-settings)
1862 (setq-local treesit-thing-settings 1893 (setq-local treesit-outline-predicate css-ts-mode--outline-predicate)
1863 `((css 1894 (setq-local treesit-thing-settings css--treesit-thing-settings)
1864 (list
1865 ,(rx bos (or "keyframe_block_list"
1866 "block"
1867 "pseudo_class_arguments"
1868 "pseudo_class_with_selector_arguments"
1869 "pseudo_class_nth_child_arguments"
1870 "pseudo_element_arguments"
1871 "feature_query"
1872 "parenthesized_query"
1873 "selector_query"
1874 "parenthesized_value"
1875 "grid_value"
1876 "arguments")
1877 eos))
1878 (sentence
1879 ,(rx bos (or "import_statement"
1880 "charset_statement"
1881 "namespace_statement"
1882 "postcss_statement"
1883 "at_rule"
1884 "declaration"
1885 )
1886 eos))
1887 (text
1888 ,(rx bos (or "comment") eos)))))
1889 1895
1890 (treesit-major-mode-setup) 1896 (treesit-major-mode-setup)
1891 1897
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."
313 (car js--treesit-thing-settings) 313 (car js--treesit-thing-settings)
314 `((defun ,js--treesit-defun-type-regexp))) 314 `((defun ,js--treesit-defun-type-regexp)))
315 ;; CSS thing settings 315 ;; CSS thing settings
316 `(css 316 (append
317 (defun ,(regexp-opt (list css--treesit-defun-type-regexp))))) 317 (car css--treesit-thing-settings)
318 `((defun ,css--treesit-defun-type-regexp))))
318 "Settings for `treesit-thing-settings'.") 319 "Settings for `treesit-thing-settings'.")
319 320
320;; We use a function instead of a variable, because 321;; We use a function instead of a variable, because
@@ -585,7 +586,7 @@ Powered by tree-sitter."
585 `((html . ,#'html-ts-mode--outline-predicate) 586 `((html . ,#'html-ts-mode--outline-predicate)
586 ;; TODO: add a predicate like for html above 587 ;; TODO: add a predicate like for html above
587 (javascript . "\\`function_declaration\\'") 588 (javascript . "\\`function_declaration\\'")
588 (css . "\\`rule_set\\'"))) 589 (css . ,css-ts-mode--outline-predicate)))
589 590
590 (treesit-major-mode-setup) 591 (treesit-major-mode-setup)
591 592