unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Vincenzo Pupillo <v.pupillo@gmail.com>
Cc: 74525-done@debbugs.gnu.org
Subject: bug#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.
Date: Thu, 28 Nov 2024 20:49:07 -0800	[thread overview]
Message-ID: <765A50F2-5E83-4F03-A251-DA6BC45BB259@gmail.com> (raw)
In-Reply-To: <2997394.vuYhMxLoTh@3-191.divsi.unimi.it>

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



> On Nov 27, 2024, at 1:12 AM, Vincenzo Pupillo <v.pupillo@gmail.com> wrote:
> 
> Please consider this patch and discard the previous one.
> 
> Thank you.
> Vincenzo
> 
> In data lunedì 25 novembre 2024 11:45:47 Ora standard dell’Europa centrale, Vincenzo Pupillo ha scritto:
>> Ciao,
>> PHP 8.4 has just been released. This patch supports a feature just introduced
>> in tree-sitter-php, the 'property_hook'.
>> It also improves both indentation and syntax highlighting of CSS and 
>> JavaScript blocks.
>> 
>> Thank you.
>> 
>> Vincenzo

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improved-support-for-PHP-8.4-and-more-reliable-inden.patch --]
[-- Type: text/x-patch; x-unix-mode=0644; name="0001-Improved-support-for-PHP-8.4-and-more-reliable-inden.patch", Size: 5643 bytes --]

From 358c14128943e3fa1e76439e5cab51979c6c677d Mon Sep 17 00:00:00 2001
From: Vincenzo Pupillo <v.pupillo@gmail.com>
Date: Mon, 25 Nov 2024 11:06:02 +0100
Subject: [PATCH] Improved support for PHP 8.4 and more reliable indentation.

Added support for PHP 8.4 property hook. More reliable CSS and
Javascript syntax indentation when there are attributes in <script> and
<style>.

* lisp/progmodes/php-ts-mode.el
(php-ts-mode--language-source-alist): Switch to the latest php grammar.
(php-ts-mode--js-css-tag-bol): CSS and Javascript indentation is now
more more reliable in different formatting styles.
(php-ts-mode--test-property-hook-clause-p): New function that tests
property_hook support.
(php-ts-mode--font-lock-settings): Use the new function.
(php-ts-mode--colorize-css-value): The function now behaves exactly like
the one in css-ts-mode.
(php-ts-mode--feature-list): Changed the list to match css-ts-mode.
---
 lisp/progmodes/php-ts-mode.el | 48 +++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el
index f9fd03cbf72..6052c79ccf3 100644
--- a/lisp/progmodes/php-ts-mode.el
+++ b/lisp/progmodes/php-ts-mode.el
@@ -84,7 +84,7 @@
 
 ;;; Install treesitter language parsers
 (defvar php-ts-mode--language-source-alist
-  '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.5" "php/src"))
+  '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.23.11" "php/src"))
     (phpdoc . ("https://github.com/claytonrcarter/tree-sitter-phpdoc"))
     (html . ("https://github.com/tree-sitter/tree-sitter-html"  "v0.23.0"))
     (javascript . ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.23.0"))
@@ -477,16 +477,20 @@ php-ts-mode--first-sibling
               (treesit-node-start parent)
               (line-end-position))))))
 
-(defun php-ts-mode--js-css-tag-bol (node _parent &rest _)
+(defun php-ts-mode--js-css-tag-bol (_node parent &rest _)
   "Find the first non-space characters of html tags <script> or <style>.
 
-If NODE is nil return `line-beginning-position'.  PARENT is ignored.
-NODE is the node to match and PARENT is its parent."
-  (if (null node)
-      (line-beginning-position)
-    (save-excursion
-      (goto-char (treesit-node-start node))
-      (re-search-backward "<script>\\|<style>" nil t))))
+Return `line-beginning-position' when `treesit-node-at' is HTML or PHP.
+Otherwise go to the PARENT and search backward for <script> or <style> tags.
+Should be used only for Javascript or CSS indenting rules.
+NODE, ignored, is the node to match and PARENT is its parent."
+  (let ((lang (treesit-language-at (point))))
+    (if (or (eq lang 'javascript)
+	    (eq lang 'css))
+	(save-excursion
+	  (goto-char (treesit-node-start parent))
+	  (re-search-backward "<script.*>\\|<style.*>" nil t))
+      (line-beginning-position))))
 
 (defun php-ts-mode--parent-eol (_node parent &rest _)
   "Find the last non-space characters of the PARENT of the current NODE.
@@ -840,6 +844,11 @@ php-ts-mode--test-visibility-modifier-operation-clause-p
   (ignore-errors
     (progn (treesit-query-compile 'php "(visibility_modifier (operation))" t) t)))
 
+(defun php-ts-mode--test-property-hook-clause-p ()
+  "Return t if property_hook is a named node, nil otherwise."
+  (ignore-errors
+    (progn (treesit-query-compile 'php "(property_hook)" t) t)))
+
 (defun php-ts-mode--font-lock-settings ()
   "Tree-sitter font-lock settings."
   (treesit-font-lock-rules
@@ -948,6 +957,8 @@ php-ts-mode--font-lock-settings
       name: (_) @font-lock-type-face)
      (function_definition
       name: (_) @font-lock-function-name-face)
+     ,@(when (php-ts-mode--test-property-hook-clause-p)
+	 '((property_hook (name) @font-lock-function-name-face)))
      (method_declaration
       name: (_) @font-lock-function-name-face)
      (method_declaration
@@ -1108,14 +1119,13 @@ php-ts-mode--colorize-css-value
            (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)))
+	  (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)))))))
     (treesit-fontify-with-override
      (treesit-node-start node) (treesit-node-end node)
      'font-lock-variable-name-face
@@ -1372,14 +1382,14 @@ php-ts-mode--feature-list
      ;; PHPDOC specific
      document
      phpdoc-error)
-    (keyword string type name)
+    (keyword string property type name)
     (;; common
      attribute assignment constant escape-sequence function-scope
      base-clause literal variable-name variable
      ;; Javascript specific
      jsx number pattern string-interpolation)
     (;; common
-     argument bracket delimiter error function-call operator property
+     argument bracket delimiter error function-call operator
      ;; Javascript specific
      function)))
 
-- 
2.47.0


[-- Attachment #3: Type: text/plain, Size: 61 bytes --]


Thanks! Since this is all fixes. I pushed to emacs-30.

Yuan

      reply	other threads:[~2024-11-29  4:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-25 10:45 bug#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation Vincenzo Pupillo
2024-11-27  9:12 ` Vincenzo Pupillo
2024-11-29  4:49   ` Yuan Fu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=765A50F2-5E83-4F03-A251-DA6BC45BB259@gmail.com \
    --to=casouri@gmail.com \
    --cc=74525-done@debbugs.gnu.org \
    --cc=v.pupillo@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).