* bug#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.
@ 2024-11-25 10:45 Vincenzo Pupillo
2024-11-27 9:12 ` Vincenzo Pupillo
0 siblings, 1 reply; 3+ messages in thread
From: Vincenzo Pupillo @ 2024-11-25 10:45 UTC (permalink / raw)
To: 74525
[-- Attachment #1: Type: text/plain, Size: 235 bytes --]
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
[-- Attachment #2: 0001-Improved-support-for-PHP-8.4-and-more-reliable-inden.patch --]
[-- Type: text/x-patch, Size: 5478 bytes --]
From ec8a2e49bae788a98147bbfaff460f12e29b5901 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 and highlighting.
* 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..d090c068d31 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.
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
0 siblings, 1 reply; 3+ messages in thread
From: Vincenzo Pupillo @ 2024-11-27 9:12 UTC (permalink / raw)
To: 74525; +Cc: Vincenzo Pupillo
[-- Attachment #1: Type: text/plain, Size: 456 bytes --]
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
[-- Attachment #2: 0001-Improved-support-for-PHP-8.4-and-more-reliable-inden.patch --]
[-- Type: text/x-patch, Size: 5515 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* bug#74525: 30.0.92; [PATCH]: php-ts-mode: Improved support for PHP 8.4 and more reliable indentation.
2024-11-27 9:12 ` Vincenzo Pupillo
@ 2024-11-29 4:49 ` Yuan Fu
0 siblings, 0 replies; 3+ messages in thread
From: Yuan Fu @ 2024-11-29 4:49 UTC (permalink / raw)
To: Vincenzo Pupillo; +Cc: 74525-done
[-- 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-11-29 4:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.