Subject: 31.0.50; [PATCH] mhtml-ts-mode: fix indentation bugs and better CSS colouring.

From: Vincenzo Pupillo <[email-masked]>
Date: Wed, 26 Feb 2025 21:21:49 +0100

Ciao,
The attached patch fixes some indentation blocking bugs. It also adds the 
coloring of "color_value" for CSS.
The discussion took place in this thread https://lists.gnu.org/archive/html/
emacs-devel/2025-02/msg00610.html

Thanks.

Vincenzo

>From d646a4039372f6f55d7860cee076bd718e05097e Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <[email-masked]>
Date: Wed, 19 Feb 2025 21:47:23 +0100
Subject: [PATCH] Fix CSS indentation, added support for CSS 'color_value'.

* lisp/textmodes/mhtml-ts-mode.el
(mhtml-ts-mode--colorize-css-value): Added 'color_value' node, refactoring.
(mhtml-ts-mode--treesit-font-lock-settings): Added 'color_value' node.
(mhtml-ts-mode--treesit-indent-rules): Removed the old comment and
fixed the CSS indentation rule.
---
 lisp/textmodes/mhtml-ts-mode.el | 37 +++++++++++++++++----------------
 1 file changed, 19 insertions(+), 18 deletions(-)

diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el
index 83f8879f427..211ccccb88a 100644
--- a/lisp/textmodes/mhtml-ts-mode.el
+++ b/lisp/textmodes/mhtml-ts-mode.el
@@ -232,21 +232,23 @@ mhtml-ts-mode--language-at-point
 (defun mhtml-ts-mode--colorize-css-value (node override start end &rest _)
   "Colorize CSS property value like `css--fontify-region'.
 For NODE, OVERRIDE, START, and END, see `treesit-font-lock-rules'."
-  (if (and mhtml-ts-mode-css-fontify-colors
-           (string-equal "plain_value" (treesit-node-type node)))
-      (let ((color (css--compute-color start (treesit-node-text node t))))
-        (when color
-          (with-silent-modifications
-            (add-text-properties
-             (treesit-node-start node) (treesit-node-end node)
-             (list 'face (list :background color
-                               :foreground (readable-foreground-color
-                                            color)
-                               :box '(:line-width -1)))))))
+  (let ((node-start (treesit-node-start node))
+	(node-end (treesit-node-end node)))
     (treesit-fontify-with-override
-     (treesit-node-start node) (treesit-node-end node)
+     node-start node-end
      'font-lock-variable-name-face
-     override start end)))
+     override start end)
+    ;; apply color if required
+    (when-let* ((ok (and mhtml-ts-mode-css-fontify-colors
+			 (member (treesit-node-type node) '("plain_value" "color_value"))))
+		(color (css--compute-color start (treesit-node-text node t))))
+	(with-silent-modifications
+	  (add-text-properties
+	   node-start node-end
+	   (list 'face (list :background color
+                             :foreground (readable-foreground-color
+					  color)
+                             :box '(:line-width -1))))))))
 
 ;; Embedded languages should be indented according to the language
 ;; that embeds them.
@@ -293,8 +295,8 @@ mhtml-ts-mode--treesit-font-lock-settings
             :language 'css
             :override t
             :feature 'variable
-            '((plain_value) @font-lock-variable-name-face
-              (plain_value) @mhtml-ts-mode--colorize-css-value))
+            '((plain_value) @mhtml-ts-mode--colorize-css-value
+              (color_value) @mhtml-ts-mode--colorize-css-value))
            css--treesit-settings))
   "Settings for `treesit-font-lock-settings'.")
 
@@ -338,9 +340,8 @@ mhtml-ts-mode--treesit-indent-rules
             `((css ((parent-is "stylesheet")
                     mhtml-ts-mode--js-css-tag-bol
                     mhtml-ts-mode--js-css-indent-offset)))
-            css--treesit-indent-rules 'prepend)
-           :replace))
-  "Settings for `treesit-simple-indent-rules'.")
+            css--treesit-indent-rules
+	    :prepend))))
 
 (defvar mhtml-ts-mode--treesit-aggregated-simple-imenu-settings
   `((html ,@html-ts-mode--treesit-simple-imenu-settings)
-- 
2.48.1