From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vincenzo Pupillo Newsgroups: gmane.emacs.bugs Subject: bug#71724: 30.0.50; [PATCH] php-ts-mode: Colorize CSS property value like `css--fontify-region' Date: Sat, 22 Jun 2024 23:36:13 +0200 Message-ID: <2215304.Hq7AAxBmiT@fedora> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3618128.aCxCBeP46V" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11611"; mail-complaints-to="usenet@ciao.gmane.io" To: 71724@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 22 23:37:27 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sL8QI-0002vV-Pl for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 22 Jun 2024 23:37:26 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sL8Px-0004oY-DF; Sat, 22 Jun 2024 17:37:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sL8Pv-0004o7-QB for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:37:03 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sL8Pv-00069E-HR for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:37:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sL8Pu-0005Ky-Fc for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:37:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vincenzo Pupillo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 22 Jun 2024 21:37:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71724 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.171909218020448 (code B ref -1); Sat, 22 Jun 2024 21:37:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Jun 2024 21:36:20 +0000 Original-Received: from localhost ([127.0.0.1]:32910 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL8PE-0005Jj-70 for submit@debbugs.gnu.org; Sat, 22 Jun 2024 17:36:20 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:47776) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sL8PC-0005Jb-LB for submit@debbugs.gnu.org; Sat, 22 Jun 2024 17:36:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sL8PC-0004kT-6n for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:36:18 -0400 Original-Received: from mail-lj1-x233.google.com ([2a00:1450:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sL8PA-00065I-FB for bug-gnu-emacs@gnu.org; Sat, 22 Jun 2024 17:36:17 -0400 Original-Received: by mail-lj1-x233.google.com with SMTP id 38308e7fff4ca-2eaafda3b5cso33227071fa.3 for ; Sat, 22 Jun 2024 14:36:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719092175; x=1719696975; darn=gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=S5EtkX+886HhOFSbl/Yz97vGxreOjLpapgkM5TKfqlU=; b=KBHttf9I7/gkxvwg+xoqkMDx6H0IYOBNLn8qwZGq+d2jI7ZwHzx24+iW38GjX3Lp7F Mj65zzB2Szm0YIbQEuDZ/d8ZvszT2Rmw5nHGF/uSOvMJS56dx5oUcMo60bN9W3IknYks jFtCaREODQG+1GEmGlhOXZ4WITgs+Rr06bMyoHAdVx/axZT45fjdk8X2GEvkZtnCg17V m355NO8UQVLhuJliAcx84EzH1YwQeO8rda9R9ON+rv+sb1BLH+hJONfIlqJxrNH26QIs oogYgpyYBu+LkD5t5X01+689afLEoDqzK+oBld4tAkMSXJWRHQdIZMOPXX4F2aLnAbTo 3J8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719092175; x=1719696975; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=S5EtkX+886HhOFSbl/Yz97vGxreOjLpapgkM5TKfqlU=; b=vt7/2qXYOuptVWDaIG6dyOZsICNUTiVlJpP6cVe0WCuZz+XeHNdENkoNjH2kEZ1yiA O1R3Wrn3si1DUrEudS5NmaNrisyOAM+AgBgL2ZVVFpazcP9fcHDISiEmKDS6ACu2fwxX mthvqeHITm5/V45RY99zXDhjkpkKw1PrP7VzLp/xjBBWoUiNAcmDvz6EUv8bZbOxIwxI EshSXT1RHOiYJeCswR/8/xd7iGePw6zvu21SoyoWPvXgw7A7a2n0MsnVWsgReBdyg1zZ LOYjTHj0HFRFq2A+yzdkRZBZca8/ixkhIUkWZTYhqetBE4JteutjCMehDfMs39dKfqAu Ti5g== X-Gm-Message-State: AOJu0YwjjtYnrrnioNmdx3cOXQhGfElwZssFDqTG2qgAgX28JkMvEhK7 9b3Lw7BY8hjqbbUoGmuo2PbHOCwM3n9VDh0R8fB9ruIE9NxVhBAn7AwHSSmp X-Google-Smtp-Source: AGHT+IELs8xWvcPY4jdD7/b0v44k1rTfJHZKv4NUzt1vpnqL1Hkh+D6yALg5Ca21YiCl6rvSiofGSA== X-Received: by 2002:a2e:8744:0:b0:2ec:5736:e903 with SMTP id 38308e7fff4ca-2ec5956b8a7mr7190751fa.46.1719092174303; Sat, 22 Jun 2024 14:36:14 -0700 (PDT) Original-Received: from fedora.localnet (2-230-139-124.ip202.fastwebnet.it. [2.230.139.124]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-57d303da378sm2729983a12.18.2024.06.22.14.36.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 22 Jun 2024 14:36:13 -0700 (PDT) Received-SPF: pass client-ip=2a00:1450:4864:20::233; envelope-from=v.pupillo@gmail.com; helo=mail-lj1-x233.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:287739 Archived-At: This is a multi-part message in MIME format. --nextPart3618128.aCxCBeP46V Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" 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 --nextPart3618128.aCxCBeP46V Content-Disposition: attachment; filename="0001-Colorize-CSS-property-value-like-css-fontify-region.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="x-UTF_8J"; name="0001-Colorize-CSS-property-value-like-css-fontify-region.patch" >From 46c7e8adb0adb107892531ea067ba75256720a59 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo 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 --nextPart3618128.aCxCBeP46V--