]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix CSS indentation, added support for CSS 'color_value'.
authorVincenzo Pupillo <v.pupillo@gmail.com>
Wed, 19 Feb 2025 20:47:23 +0000 (21:47 +0100)
committerEshel Yaron <me@eshelyaron.com>
Fri, 28 Feb 2025 11:19:32 +0000 (12:19 +0100)
* 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 (bug#76597).

(cherry picked from commit 5f1a019d26f475f35fe8efc583749321affb6060)

lisp/textmodes/mhtml-ts-mode.el

index 33c5f3c3019ada0cd83872b34c8e02d0acd25346..09fbb4c1cad51e44627fb3e34b596e213983ed14 100644 (file)
@@ -232,21 +232,23 @@ Optional ARGUMENTS to to be passed to it."
 (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 @@ NODE and PARENT are ignored."
             :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 @@ NODE and PARENT are ignored."
             `((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)