unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71724: 30.0.50; [PATCH] php-ts-mode: Colorize CSS property value like `css--fontify-region'
@ 2024-06-22 21:36 Vincenzo Pupillo
  2024-06-23  5:06 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Vincenzo Pupillo @ 2024-06-22 21:36 UTC (permalink / raw)
  To: 71724

[-- Attachment #1: Type: text/plain, Size: 309 bytes --]

Hi, 
this patch adds a new feature to colorize a property when it's value is a text 
that represents a CSS color. It will be fontified such that its background is 
the color itself, like in 'cs-ts-mode'.
A new custom var 'php-ts-mode-css-fontify-colors' can be used to toggle this 
behavior.

Thanks.
Vincenzo

[-- Attachment #2: 0001-Colorize-CSS-property-value-like-css-fontify-region.patch --]
[-- Type: text/x-patch, Size: 4091 bytes --]

From 46c7e8adb0adb107892531ea067ba75256720a59 Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
Date: Sat, 22 Jun 2024 23:11:17 +0200
Subject: [PATCH] Colorize CSS property value like `css--fontify-region'

If the value of a property is text representing a CSS color, it will be
fontified such that its background is the color itself.
'php-ts-mode-css-fontify-colors' can be used to disable this behaviour.

* lisp/progmodes/php-ts-mode.el (php-ts-mode-css-fontify-colors):
  New custom var.
* lisp/progmodes/php-ts-mode.el (php-ts-mode--colorize-css-value):
  New function.
* lisp/progmodes/php-ts-mode.el (php-ts-mode): Use the new function.
---
 lisp/progmodes/php-ts-mode.el | 44 ++++++++++++++++++++++++++++++++---
 1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index f1dfac59c2e..d2d8377ee88 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -121,6 +121,16 @@ php-ts-mode-js-css-indent-offset
   :type 'integer
   :safe 'integerp)
 
+(defcustom php-ts-mode-css-fontify-colors t
+  "Whether CSS colors should be fontified using the color as the background.
+When non-nil, a text representing CSS color will be fontified
+such that its background is the color itself.
+Works like `css--fontify-region'."
+  :tag "PHP colors the CSS properties values."
+  :version "30.1"
+  :type 'boolean
+  :safe 'booleanp)
+
 (defcustom php-ts-mode-php-executable (or (executable-find "php") "/usr/bin/php")
   "The location of PHP executable."
   :tag "PHP Executable"
@@ -999,6 +1009,26 @@ php-ts-mode--phpdoc-font-lock-settings
    '((variable_name (name) @font-lock-variable-name-face)))
   "Tree-sitter font-lock settings for phpdoc.")
 
+(defun php-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 php-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
+          (treesit-fontify-with-override
+           (treesit-node-start node) (treesit-node-end node)
+           (list 'face
+                 (list :background color
+                       :foreground (readable-foreground-color
+                                    color)
+                       :box '(:line-width -1)))
+           override start end)))
+    (treesit-fontify-with-override
+     (treesit-node-start node) (treesit-node-end node)
+     'font-lock-variable-name-face
+     override start end)))
+
 (defun php-ts-mode--fontify-error (node override start end &rest _)
   "Fontify the error nodes.
 For NODE, OVERRIDE, START, and END, see `treesit-font-lock-rules'."
@@ -1393,12 +1423,20 @@ php-ts-mode
                   ("Constant" "\\`const_element\\'" nil nil)))
 
     ;; Font-lock.
-    (setq-local treesit-font-lock-settings (php-ts-mode--font-lock-settings))
     (setq-local treesit-font-lock-settings
-                (append treesit-font-lock-settings
+                (append (php-ts-mode--font-lock-settings)
                         php-ts-mode--custom-html-font-lock-settings
                         js--treesit-font-lock-settings
-                        css--treesit-settings
+                        (append
+                         ;; Rule for coloring CSS property values.
+                         ;; Placed before `css--treesit-settings'
+                         ;; to win against the same rule contained therein.
+                         (treesit-font-lock-rules
+                          :language 'css
+                          :override t
+                          :feature 'variable
+                          '((plain_value) @php-ts-mode--colorize-css-value))
+                         css--treesit-settings)
                         php-ts-mode--phpdoc-font-lock-settings))
 
     (setq-local treesit-font-lock-feature-list php-ts-mode--feature-list)
-- 
2.45.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* bug#71724: 30.0.50; [PATCH] php-ts-mode: Colorize CSS property value like `css--fontify-region'
  2024-06-22 21:36 bug#71724: 30.0.50; [PATCH] php-ts-mode: Colorize CSS property value like `css--fontify-region' Vincenzo Pupillo
@ 2024-06-23  5:06 ` Eli Zaretskii
  2024-06-23 10:11   ` Vincenzo Pupillo
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-06-23  5:06 UTC (permalink / raw)
  To: Vincenzo Pupillo; +Cc: 71724-done

> From: Vincenzo Pupillo <v.pupillo@gmail.com>
> Date: Sat, 22 Jun 2024 23:36:13 +0200
> 
> this patch adds a new feature to colorize a property when it's value is a text 
> that represents a CSS color. It will be fontified such that its background is 
> the color itself, like in 'cs-ts-mode'.
> A new custom var 'php-ts-mode-css-fontify-colors' can be used to toggle this 
> behavior.

Thanks, installed, and closing the bug.

Please in the future observe our conventions for the commit log
messages:

> Subject: [PATCH] Colorize CSS property value like `css--fontify-region'
> 
> If the value of a property is text representing a CSS color, it will be
> fontified such that its background is the color itself.
> 'php-ts-mode-css-fontify-colors' can be used to disable this behaviour.

These lines are too long.  They will be indented by a TAB in the
generated ChangeLog file, so they should preferably be no longer than
65 characters.

> * lisp/progmodes/php-ts-mode.el (php-ts-mode-css-fontify-colors):
>   New custom var.
 ^^^
Please don't leave this whitespace at the beginning of lines.

> * lisp/progmodes/php-ts-mode.el (php-ts-mode): Use the new function.

This line is also too long.

I usually correct any log messages that need it, but if you observe
these conventions better, it will make my job easier.

Thanks.





^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#71724: 30.0.50; [PATCH] php-ts-mode: Colorize CSS property value like `css--fontify-region'
  2024-06-23  5:06 ` Eli Zaretskii
@ 2024-06-23 10:11   ` Vincenzo Pupillo
  2024-06-23 10:15     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Vincenzo Pupillo @ 2024-06-23 10:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 71724-done

In data domenica 23 giugno 2024 07:06:10 CEST, Eli Zaretskii ha scritto:
> > From: Vincenzo Pupillo <v.pupillo@gmail.com>
> > Date: Sat, 22 Jun 2024 23:36:13 +0200
> > 
> > this patch adds a new feature to colorize a property when it's value is a
> > text that represents a CSS color. It will be fontified such that its
> > background is the color itself, like in 'cs-ts-mode'.
> > A new custom var 'php-ts-mode-css-fontify-colors' can be used to toggle
> > this behavior.
> 
> Thanks, installed, and closing the bug.
> 
> Please in the future observe our conventions for the commit log
> 
> messages:
> > Subject: [PATCH] Colorize CSS property value like `css--fontify-region'
> > 
> > If the value of a property is text representing a CSS color, it will be
> > fontified such that its background is the color itself.
> > 'php-ts-mode-css-fontify-colors' can be used to disable this behaviour.
> 
> These lines are too long.  They will be indented by a TAB in the
> generated ChangeLog file, so they should preferably be no longer than
> 65 characters.
> 
> > * lisp/progmodes/php-ts-mode.el (php-ts-mode-css-fontify-colors):
> >   New custom var.
> 
>  ^^^
> Please don't leave this whitespace at the beginning of lines.
> 
> > * lisp/progmodes/php-ts-mode.el (php-ts-mode): Use the new function.
> 
> This line is also too long.
> 
> I usually correct any log messages that need it, but if you observe
> these conventions better, it will make my job easier.
> 
> Thanks.
I apologize, I will be more accurate with the commit log messages.
Thank you very much Eli.

Vincenzo








^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#71724: 30.0.50; [PATCH] php-ts-mode: Colorize CSS property value like `css--fontify-region'
  2024-06-23 10:11   ` Vincenzo Pupillo
@ 2024-06-23 10:15     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-06-23 10:15 UTC (permalink / raw)
  To: Vincenzo Pupillo; +Cc: 71724

> From: Vincenzo Pupillo <v.pupillo@gmail.com>
> Cc: 71724-done@debbugs.gnu.org
> Date: Sun, 23 Jun 2024 12:11:07 +0200
> 
> I apologize, I will be more accurate with the commit log messages.

No need to apologize, we aren't born with this knowledge.

Thank you for you continuing contributions.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-23 10:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-22 21:36 bug#71724: 30.0.50; [PATCH] php-ts-mode: Colorize CSS property value like `css--fontify-region' Vincenzo Pupillo
2024-06-23  5:06 ` Eli Zaretskii
2024-06-23 10:11   ` Vincenzo Pupillo
2024-06-23 10:15     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).