mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-06 06:20:55 -08:00
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).
This commit is contained in:
parent
3e1d7e0334
commit
5f1a019d26
1 changed files with 19 additions and 18 deletions
|
|
@ -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
|
||||
(let ((node-start (treesit-node-start node))
|
||||
(node-end (treesit-node-end node)))
|
||||
(treesit-fontify-with-override
|
||||
node-start node-end
|
||||
'font-lock-variable-name-face
|
||||
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
|
||||
(treesit-node-start node) (treesit-node-end node)
|
||||
node-start node-end
|
||||
(list 'face (list :background color
|
||||
:foreground (readable-foreground-color
|
||||
color)
|
||||
:box '(:line-width -1)))))))
|
||||
(treesit-fontify-with-override
|
||||
(treesit-node-start node) (treesit-node-end node)
|
||||
'font-lock-variable-name-face
|
||||
override start end)))
|
||||
: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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue