From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#72796: 30.0.50; [PATCH] php-ts-mode: Improved font locking Date: Mon, 26 Aug 2024 00:52:41 -0700 Message-ID: <9FFE9897-83A8-4760-8BFA-F1EDC4195D02@gmail.com> References: <26542402.1r3eYUQgxm@fedora> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51\)) Content-Type: multipart/mixed; boundary="Apple-Mail=_920B0036-609D-482D-882B-85E04419B71B" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38590"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 72796-done@debbugs.gnu.org To: Vincenzo Pupillo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 26 09:54:35 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 1siUYd-0009sW-7h for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 26 Aug 2024 09:54:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1siUYG-0001vr-8l; Mon, 26 Aug 2024 03:54:12 -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 1siUYF-0001vO-5n for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 03:54:11 -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 1siUYE-00014s-Sc for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 03:54:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:Date:Mime-Version:From:To:Subject; bh=XyLqGzpHWD1ohF3N0zfVy+s8Cgghjxf2WGBQC51l9Ug=; b=QthFs3P4epkZzg1IoJXySS5TL0h5jTaWnXCxZ349qCiYpc9rN3fe1XovdDR8TtEpG4HkSmaUmGwb20QnPR0ZmquIcO8oimVbzWKB8dV5KcMkQnQ+yd4ovMN1lDh7CTo1s6MKEws+cTUcOn0QTkdFULb/bN76QZCchyTP+RPkLDvNSw159Z+/v5lshp2xeQU7t5BvHcTSZBqxdZbkDs74WAQNICYgflIwbqFh+99xlU/3FRTPM3cDwJ7U4vBXlZsDpi14GMHw1rij9kglEF1OlJj+ZDtVxNJld9xLU/5Xg8VuTVZTAlIwbbdav/wcQ3rRegLv4b3010QOVp2sRulEfQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1siUZ3-00045Z-Py for bug-gnu-emacs@gnu.org; Mon, 26 Aug 2024 03:55:01 -0400 Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 26 Aug 2024 07:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 72796 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Mail-Followup-To: 72796@debbugs.gnu.org, casouri@gmail.com, v.pupillo@gmail.com Original-Received: via spool by 72796-done@debbugs.gnu.org id=D72796.172465889215685 (code D ref 72796); Mon, 26 Aug 2024 07:55:01 +0000 Original-Received: (at 72796-done) by debbugs.gnu.org; 26 Aug 2024 07:54:52 +0000 Original-Received: from localhost ([127.0.0.1]:43643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1siUYu-00044s-3Z for submit@debbugs.gnu.org; Mon, 26 Aug 2024 03:54:52 -0400 Original-Received: from mail-pf1-f169.google.com ([209.85.210.169]:60528) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1siUYs-00044c-BQ for 72796-done@debbugs.gnu.org; Mon, 26 Aug 2024 03:54:51 -0400 Original-Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-71433cba1b7so2850268b3a.0 for <72796-done@debbugs.gnu.org>; Mon, 26 Aug 2024 00:53:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724658773; x=1725263573; darn=debbugs.gnu.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=XyLqGzpHWD1ohF3N0zfVy+s8Cgghjxf2WGBQC51l9Ug=; b=VQrVB5+RwKSfbcqqrIW18bl230JOh9Fd8Q5LVmsGLtP8cjOWdWWwip5KrXhI2VVSC6 wjnGv1EKB1hgxyZaovbncD81BuidurIBjS0MY2RT0GFmFKxJ8Hwc2hERnqiNJRXgmMIo JrKuC0ORdYImyRLozMU5JkJQ67r3uz0Uh7AMi06r3jbbErKMZtlULgKkPzVHWJSQJngl jeyYAYjdIxrZkmxWJ42myunRuZiAiPQNIvmOfxJVFFQ1yiFnhvmOn91FDiG1gilozTpl aMxvkZlOFkCf4W04s5qZJzbG6txYJ5ZNZfzcjBgoQnyf3UTj4Ekdwj9NOzvNFrT2cBBh UqOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724658773; x=1725263573; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=XyLqGzpHWD1ohF3N0zfVy+s8Cgghjxf2WGBQC51l9Ug=; b=SYrdYV7QrPYqX/qw0HNxJzxG0Mxe/ISsrqbcl6G3eAXGDxW69NTHYFlkr71+e3M8Mp BpgmJ7rfMGRNwE0CIqyoAR9taEZ6KsAKmtYvv2ebpinkGta3V5kdtfRoou+xgcrRfgIw ZNqWAQ1onQH57dho+Ob0Flc+ypYcgAtS+hUApGB8AsgQReJnQjNhIkhHoSpGPAJNSIte Rf0wzmp4JYp27Ux47FWX5Q2fSCYB/0m1Yb9EQuXvN2hKTUVPyDrE3TV2tm0yma5tjX5v gY2/3oIfJfUNifuOs6QK75NXezIMimUa/5o4wV5ZwBmydZ3L75M9PBQTAHfuiW0mfA2P Ojag== X-Gm-Message-State: AOJu0YzgusHCmkAAgucp+alM/BAEUTX4NBZ0e5+sdpBuDKzY7n9AdY+m YUJNKOl4AXd/UkT7+RQWr4zCQDkm+aQqhXmbaxr/3E5wX2IqH75K X-Google-Smtp-Source: AGHT+IGQzZfW6APQrlB2gg1EGiNUsqO9jsiPMf/Nrm7YnUBNw5Q4P4S6Se4KmBXbmfCkUnRHBvufFg== X-Received: by 2002:a05:6a21:4581:b0:1c8:9749:a4c1 with SMTP id adf61e73a8af0-1cc8a084f1dmr8637581637.49.1724658773048; Mon, 26 Aug 2024 00:52:53 -0700 (PDT) Original-Received: from smtpclient.apple ([2601:646:8f81:6120:3470:5bab:363c:9aa2]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2038557e895sm62960485ad.71.2024.08.26.00.52.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Aug 2024 00:52:52 -0700 (PDT) In-Reply-To: <26542402.1r3eYUQgxm@fedora> X-Mailer: Apple Mail (2.3776.700.51) 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:290776 Archived-At: --Apple-Mail=_920B0036-609D-482D-882B-85E04419B71B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Aug 24, 2024, at 2:41=E2=80=AFPM, Vincenzo Pupillo = wrote: >=20 > Hi,=20 > This patch improves font locking, particularly for constants and some=20= > operators. It also extends compatibility to the latest version of the = PHP=20 > parser. > The patch can also be applied to version 31.0.50 . >=20 > Thanks > Vincenzo= --Apple-Mail=_920B0036-609D-482D-882B-85E04419B71B Content-Disposition: attachment; filename=0001-Improve-php-ts-mode-font-lock-and-support-latest-par.patch Content-Type: text/x-patch; x-unix-mode=0644; name="0001-Improve-php-ts-mode-font-lock-and-support-latest-par.patch" Content-Transfer-Encoding: quoted-printable =46rom 59fd3b34171f5ff17509e8c6c4e73f457ca4d038 Mon Sep 17 00:00:00 2001 From: Vincenzo Pupillo Date: Sat, 24 Aug 2024 23:16:09 +0200 Subject: [PATCH] Improve php-ts-mode font lock and support latest parser release * lisp/progmodes/php-ts-mode.el (php-ts-mode--language-source-alist): Update the parser version. * lisp/progmodes/php-ts-mode.el (php-ts-mode--parent-html-heuristic): Fix commentary. * lisp/progmodes/php-ts-mode.el (php-ts-mode--keywords): Add "exit" keyword. * lisp/progmodes/php-ts-mode.el (php-ts-mode--predefined-constant): Added math constant. * lisp/progmodes/php-ts-mode.el (php-ts-mode--font-lock-settings): New and improved rules. --- lisp/progmodes/php-ts-mode.el | 41 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lisp/progmodes/php-ts-mode.el = b/lisp/progmodes/php-ts-mode.el index 89444f0208e..3f89de14075 100644 --- a/lisp/progmodes/php-ts-mode.el +++ b/lisp/progmodes/php-ts-mode.el @@ -83,7 +83,7 @@ =20 ;;; Install treesitter language parsers (defvar php-ts-mode--language-source-alist - '((php . ("https://github.com/tree-sitter/tree-sitter-php" = "v0.22.5")) + '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.22.8" = "php/src")) (phpdoc . ("https://github.com/claytonrcarter/tree-sitter-phpdoc")) (html . ("https://github.com/tree-sitter/tree-sitter-html" = "v0.20.3")) (javascript . = ("https://github.com/tree-sitter/tree-sitter-javascript" "v0.21.2")) @@ -509,7 +509,7 @@ php-ts-mode--parent-html-heuristic (if (search-forward "" end-html t 1) 0 (+ (point) php-ts-mode-indent-offset)))) - ;; Maybe it's better to use bol, read the documentation!!! + ;; Maybe it's better to use bol? (treesit-node-start parent)))) =20 (defun php-ts-mode--array-element-heuristic (_node parent _bol &rest _) @@ -728,7 +728,7 @@ php-ts-mode--keywords '("abstract" "and" "array" "as" "break" "callable" "case" "catch" "class" "clone" "const" "continue" "declare" "default" "do" "echo" "else" "elseif" "enddeclare" "endfor" "endforeach" "endif" - "endswitch" "endwhile" "enum" "extends" "final" "finally" "fn" + "endswitch" "endwhile" "enum" "exit" "extends" "final" "finally" = "fn" "for" "foreach" "from" "function" "global" "goto" "if" "implements" "include" "include_once" "instanceof" "insteadof" "interface" "list" "match" "namespace" "new" "null" "or" "print" "private" @@ -762,6 +762,12 @@ php-ts-mode--predefined-constant "E_COMPILE_WARNING" "E_USER_ERROR" "E_USER_WARNING" "E_USER_NOTICE" "E_DEPRECATED" "E_USER_DEPRECATED" "E_ALL" "E_STRICT" + ;; math constant + "M_PI" "M_E" "M_LOG2E" "M_LOG10E" "M_LN2" "M_LN10" "M_PI_2" + "M_PI_4" "M_1_PI" "M_2_PI" "M_SQRTPI" "M_2_SQRTPI" "M_SQRT2" + "M_SQRT3" "M_SQRT1_2" "M_LNPI" "M_EULER" "PHP_ROUND_HALF_UP" + "PHP_ROUND_HALF_DOWN" "PHP_ROUND_HALF_EVEN" "PHP_ROUND_HALF_ODD" + "NAN" "INF" ;; magic constant "__COMPILER_HALT_OFFSET__" "__CLASS__" "__DIR__" "__FILE__" "__FUNCTION__" "__LINE__" "__METHOD__" "__NAMESPACE__" "__TRAIT__") @@ -785,26 +791,23 @@ php-ts-mode--font-lock-settings :feature 'constant `((boolean) @font-lock-constant-face (null) @font-lock-constant-face - ;; predefined constant or built in constant + ;; predefined constant or built in constant (part of PHP core) ((name) @font-lock-builtin-face (:match ,(rx-to-string `(: bos (or ,@php-ts-mode--predefined-constant) eos)) @font-lock-builtin-face)) ;; user defined constant ((name) @font-lock-constant-face - (:match "\\`_?[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face)) + (:match "\\`_*[A-Z][0-9A-Z_]+\\'" @font-lock-constant-face)) (const_declaration (const_element (name) @font-lock-constant-face)) - (relative_scope "self") @font-lock-builtin-face ;; declare directive (declare_directive ["strict_types" "encoding" "ticks"] = @font-lock-constant-face)) =20 :language 'php :feature 'name - `((goto_statement (name) @font-lock-constant-face) - (named_label_statement (name) @font-lock-constant-face) - (expression_statement (name) @font-lock-keyword-face - (:equal "exit" @font-lock-keyword-face))) + '((goto_statement (name) @font-lock-constant-face) + (named_label_statement (name) @font-lock-constant-face)) =20 :language 'php ;;:override t @@ -813,19 +816,21 @@ php-ts-mode--font-lock-settings =20 :language 'php :feature 'operator - `([,@php-ts-mode--operators] @font-lock-operator-face) + `((error_suppression_expression "@" @font-lock-keyword-face) + [,@php-ts-mode--operators] @font-lock-operator-face) =20 :language 'php :feature 'variable-name :override t - `(((name) @font-lock-keyword-face (:equal "this" = @font-lock-keyword-face)) + '(((name) @font-lock-keyword-face (:equal "this" = @font-lock-keyword-face)) (variable_name (name) @font-lock-variable-name-face) + (relative_scope ["parent" "self" "static"] = @font-lock-builtin-face) + (relative_scope) @font-lock-constant-face (dynamic_variable_name (name) @font-lock-variable-name-face) (member_access_expression name: (_) @font-lock-variable-name-face) (scoped_property_access_expression - scope: (name) @font-lock-constant-face) - (error_suppression_expression (name) = @font-lock-variable-name-face)) + scope: (name) @font-lock-constant-face)) =20 :language 'php :feature 'string @@ -850,7 +855,8 @@ php-ts-mode--font-lock-settings :language 'php :feature 'type :override t - '((union_type) @font-lock-type-face + '((union_type "|" @font-lock-operator-face) + (union_type) @font-lock-type-face (bottom_type) @font-lock-type-face (primitive_type) @font-lock-type-face (cast_type) @font-lock-type-face @@ -883,17 +889,18 @@ php-ts-mode--font-lock-settings ("=3D>") @font-lock-keyword-face (object_creation_expression (name) @font-lock-type-face) + (namespace_name_as_prefix "\\" @font-lock-delimiter-face) (namespace_name_as_prefix (namespace_name (name)) = @font-lock-type-face) (namespace_use_clause (name) @font-lock-property-use-face) (namespace_aliasing_clause (name) @font-lock-type-face) + (namespace_name "\\" @font-lock-delimiter-face) (namespace_name (name) @font-lock-type-face) (use_declaration (name) @font-lock-property-use-face)) =20 :language 'php :feature 'function-scope :override t - '((relative_scope) @font-lock-constant-face - (scoped_call_expression + '((scoped_call_expression scope: (name) @font-lock-constant-face) (class_constant_access_expression (name) = @font-lock-constant-face)) =20 --=20 2.46.0 --Apple-Mail=_920B0036-609D-482D-882B-85E04419B71B Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Thanks Vince! I merged your patch to emacs-30. BTW, in the future it=E2=80= =99s probably better to make the code work for both old and new grammar = versions (whenever you can), that way people who installed the old = grammar from who-knows-where can still use the mode. (I=E2=80=99m = working on some tool to make it simpler to define alternative font-lock = rules that works on multiple grammar versions.) Yuan= --Apple-Mail=_920B0036-609D-482D-882B-85E04419B71B--