From: Vincenzo Pupillo Date: Wed, 19 Feb 2025 20:47:23 +0000 (+0100) Subject: Fix CSS indentation, added support for CSS 'color_value'. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0e64b8e8ed7ef00c2dfeffc7cd0e28bace4a41ab;p=emacs.git 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 (bug#76597). (cherry picked from commit 5f1a019d26f475f35fe8efc583749321affb6060) --- diff --git a/lisp/textmodes/mhtml-ts-mode.el b/lisp/textmodes/mhtml-ts-mode.el index 33c5f3c3019..09fbb4c1cad 100644 --- a/lisp/textmodes/mhtml-ts-mode.el +++ b/lisp/textmodes/mhtml-ts-mode.el @@ -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)