diff options
| author | Vincenzo Pupillo | 2025-02-19 21:47:23 +0100 |
|---|---|---|
| committer | Juri Linkov | 2025-02-27 20:06:20 +0200 |
| commit | 5f1a019d26f475f35fe8efc583749321affb6060 (patch) | |
| tree | 716613a2aedb2fb912b42080b1eff80a243ab8cb | |
| parent | 3e1d7e0334d884a17887bd1b9ee6a9b9e3026a30 (diff) | |
| download | emacs-5f1a019d26f475f35fe8efc583749321affb6060.tar.gz emacs-5f1a019d26f475f35fe8efc583749321affb6060.zip | |
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).
| -rw-r--r-- | lisp/textmodes/mhtml-ts-mode.el | 37 |
1 files changed, 19 insertions, 18 deletions
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." | |||
| 232 | (defun mhtml-ts-mode--colorize-css-value (node override start end &rest _) | 232 | (defun mhtml-ts-mode--colorize-css-value (node override start end &rest _) |
| 233 | "Colorize CSS property value like `css--fontify-region'. | 233 | "Colorize CSS property value like `css--fontify-region'. |
| 234 | For NODE, OVERRIDE, START, and END, see `treesit-font-lock-rules'." | 234 | For NODE, OVERRIDE, START, and END, see `treesit-font-lock-rules'." |
| 235 | (if (and mhtml-ts-mode-css-fontify-colors | 235 | (let ((node-start (treesit-node-start node)) |
| 236 | (string-equal "plain_value" (treesit-node-type node))) | 236 | (node-end (treesit-node-end node))) |
| 237 | (let ((color (css--compute-color start (treesit-node-text node t)))) | ||
| 238 | (when color | ||
| 239 | (with-silent-modifications | ||
| 240 | (add-text-properties | ||
| 241 | (treesit-node-start node) (treesit-node-end node) | ||
| 242 | (list 'face (list :background color | ||
| 243 | :foreground (readable-foreground-color | ||
| 244 | color) | ||
| 245 | :box '(:line-width -1))))))) | ||
| 246 | (treesit-fontify-with-override | 237 | (treesit-fontify-with-override |
| 247 | (treesit-node-start node) (treesit-node-end node) | 238 | node-start node-end |
| 248 | 'font-lock-variable-name-face | 239 | 'font-lock-variable-name-face |
| 249 | override start end))) | 240 | override start end) |
| 241 | ;; apply color if required | ||
| 242 | (when-let* ((ok (and mhtml-ts-mode-css-fontify-colors | ||
| 243 | (member (treesit-node-type node) '("plain_value" "color_value")))) | ||
| 244 | (color (css--compute-color start (treesit-node-text node t)))) | ||
| 245 | (with-silent-modifications | ||
| 246 | (add-text-properties | ||
| 247 | node-start node-end | ||
| 248 | (list 'face (list :background color | ||
| 249 | :foreground (readable-foreground-color | ||
| 250 | color) | ||
| 251 | :box '(:line-width -1)))))))) | ||
| 250 | 252 | ||
| 251 | ;; Embedded languages should be indented according to the language | 253 | ;; Embedded languages should be indented according to the language |
| 252 | ;; that embeds them. | 254 | ;; that embeds them. |
| @@ -293,8 +295,8 @@ NODE and PARENT are ignored." | |||
| 293 | :language 'css | 295 | :language 'css |
| 294 | :override t | 296 | :override t |
| 295 | :feature 'variable | 297 | :feature 'variable |
| 296 | '((plain_value) @font-lock-variable-name-face | 298 | '((plain_value) @mhtml-ts-mode--colorize-css-value |
| 297 | (plain_value) @mhtml-ts-mode--colorize-css-value)) | 299 | (color_value) @mhtml-ts-mode--colorize-css-value)) |
| 298 | css--treesit-settings)) | 300 | css--treesit-settings)) |
| 299 | "Settings for `treesit-font-lock-settings'.") | 301 | "Settings for `treesit-font-lock-settings'.") |
| 300 | 302 | ||
| @@ -338,9 +340,8 @@ NODE and PARENT are ignored." | |||
| 338 | `((css ((parent-is "stylesheet") | 340 | `((css ((parent-is "stylesheet") |
| 339 | mhtml-ts-mode--js-css-tag-bol | 341 | mhtml-ts-mode--js-css-tag-bol |
| 340 | mhtml-ts-mode--js-css-indent-offset))) | 342 | mhtml-ts-mode--js-css-indent-offset))) |
| 341 | css--treesit-indent-rules 'prepend) | 343 | css--treesit-indent-rules |
| 342 | :replace)) | 344 | :prepend)))) |
| 343 | "Settings for `treesit-simple-indent-rules'.") | ||
| 344 | 345 | ||
| 345 | (defvar mhtml-ts-mode--treesit-aggregated-simple-imenu-settings | 346 | (defvar mhtml-ts-mode--treesit-aggregated-simple-imenu-settings |
| 346 | `((html ,@html-ts-mode--treesit-simple-imenu-settings) | 347 | `((html ,@html-ts-mode--treesit-simple-imenu-settings) |