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#71380: 30.0.50; Submitting php-ts-mode, new major mode for php Date: Wed, 12 Jun 2024 11:25:20 +0200 Message-ID: <2299968.9o76ZdvQCi@3-191.divsi.unimi.it> References: <3686989.dWV9SEqChM@3-191.divsi.unimi.it> <5638447.rdbgypaU67@fedora> <4710860.vXUDI8C0e8@fedora> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2858656.vuYhMxLoTh" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1568"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 71380@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 12 12:37: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 1sHLMF-0000A6-7B for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 12 Jun 2024 12:37:35 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sHLLq-00029T-EB; Wed, 12 Jun 2024 06:37:10 -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 1sHLLl-000290-KC for bug-gnu-emacs@gnu.org; Wed, 12 Jun 2024 06:37:05 -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 1sHLLl-0006K4-CL for bug-gnu-emacs@gnu.org; Wed, 12 Jun 2024 06:37:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sHLLk-0000fI-1G for bug-gnu-emacs@gnu.org; Wed, 12 Jun 2024 06:37:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Vincenzo Pupillo Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 12 Jun 2024 10:37:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 71380 X-GNU-PR-Package: emacs Original-Received: via spool by 71380-submit@debbugs.gnu.org id=B71380.17181885972480 (code B ref 71380); Wed, 12 Jun 2024 10:37:03 +0000 Original-Received: (at 71380) by debbugs.gnu.org; 12 Jun 2024 10:36:37 +0000 Original-Received: from localhost ([127.0.0.1]:37697 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sHLLF-0000dl-AV for submit@debbugs.gnu.org; Wed, 12 Jun 2024 06:36:37 -0400 Original-Received: from mout-u-204.mailbox.org ([80.241.59.204]:44652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sHKEx-0007CI-Ho for 71380@debbugs.gnu.org; Wed, 12 Jun 2024 05:26:02 -0400 Original-Received: from smtp102.mailbox.org (smtp102.mailbox.org [10.196.197.102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4VzgB9738Kz9tZG; Wed, 12 Jun 2024 11:25:21 +0200 (CEST) In-Reply-To: <4710860.vXUDI8C0e8@fedora> X-Mailman-Approved-At: Wed, 12 Jun 2024 06:36:28 -0400 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:287150 Archived-At: This is a multi-part message in MIME format. --nextPart2858656.vuYhMxLoTh Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" Hi Eli, this updated patch add the support for PHP var_modifier. Thanks. Vincenzo In data domenica 9 giugno 2024 22:36:35 CEST, Vincenzo Pupillo ha scritto: > Sorry. The correct patch is this one. I had forgotten to extend the commit by > adding documentation about the side effect. > Thanks. > Vincenzo > > In data domenica 9 giugno 2024 21:37:40 CEST, Vincenzo Pupillo ha scritto: > > In data domenica 9 giugno 2024 19:49:24 CEST, Eli Zaretskii ha scritto: > > > > From: Vincenzo Pupillo > > > > Cc: 71380@debbugs.gnu.org > > > > Date: Sun, 09 Jun 2024 19:23:05 +0200 > > > > > > > > > > > Thanks, but does this replace both patches you sent in a previous > > > > > > > message? See > > > > > > > https://debbugs.gnu.org/cgi/bugreport.cgi?bug=71380#23 > > > > > > > Or does this replace only one of the two, and the other one is > > > > > > > still > > > > > > > needed? > > > > > > > > > > > > Replace only one. The other is still needed. I made a separate > > > > > > patch, > > > > > > waiting to hear if I should open another bug for html-ts-mode. > > > > > > > > > > Would you mind posting both patches together, updated so that I could > > > > > install them both? And note that I just found a strange mistake(?) in > > > > > the second patch. > > > > > > > > > > Thanks. > > > > > > > > Hi Eli, > > > > sorry. I made a mistake with the second patch. > > > > The warning Andrea reported was actually due to the (require > > > > 'html-ts-mode) at the beginning of php-ts-mode. > > > > I then use a solution similar to elixir-ts-mode, the (require > > > > 'html-ts-mode) is done only after checking that the parser exists. > > > > > > But the patch you posted now doesn't include the HTML part, does it? > > > > > > is the patch self-contained, or does it still need the second patch? > > > > It is self-contained. You can delete the patch for html-ts-mode, it is no > > longer needed > > > > > > There is one problem I don't know how to solve: enabling php-ts-mode, > > > > because of the require html-ts-mode, the major mode for html changes > > > > from > > > > mhtml-mode to html-ts-mode. > > > > Can you tell me how to fix this? > > > > > > Just document this side effect, so that users know. > > > > Ok done. > > > > Thank you. > > Vincenzo > > --nextPart2858656.vuYhMxLoTh Content-Disposition: attachment; filename="0001-Add-php-ts-mode.patch" Content-Transfer-Encoding: quoted-printable Content-Type: text/x-patch; charset="x-UTF_8J"; name="0001-Add-php-ts-mode.patch" =46rom d15a81a383660ede80b7fef46e573b0147e4261d Mon Sep 17 00:00:00 2001 =46rom: Vincenzo Pupillo Date: Fri, 7 Jun 2024 12:39:03 +0200 Subject: [PATCH] Add php-ts-mode * etc/NEWS: Mention the new mode. * lisp/progmodes/php-ts-mode.el: New file. =2D-- etc/NEWS | 5 + lisp/progmodes/php-ts-mode.el | 1647 +++++++++++++++++++++++++++++++++ 2 files changed, 1652 insertions(+) create mode 100644 lisp/progmodes/php-ts-mode.el diff --git a/etc/NEWS b/etc/NEWS index 808cd0562db..067963b7a26 100644 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -1933,6 +1933,11 @@ A major mode based on the tree-sitter library for ed= iting Elixir files. *** New major mode 'lua-ts-mode'. A major mode based on the tree-sitter library for editing Lua files. =20 +--- +*** New major mode 'php-ts-mode'. +A major mode based on the tree-sitter library for editing PHP files. + + ** Minibuffer and Completions =20 +++ diff --git a/lisp/progmodes/php-ts-mode.el b/lisp/progmodes/php-ts-mode.el new file mode 100644 index 00000000000..3473057edd4 =2D-- /dev/null +++ b/lisp/progmodes/php-ts-mode.el @@ -0,0 +1,1647 @@ +;;; php-ts-mode.el --- Major mode for editing PHP files using tree-sitter = =2D*- lexical-binding: t; -*- + +;; Copyright (C) 2024 Free Software Foundation, Inc. + +;; Author: Vincenzo Pupillo +;; Maintainer: Vincenzo Pupillo +;; Created: Jun 2024 +;; Keywords: PHP language tree-sitter + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see . + +;;; Commentary: +;; +;; This package provides `php-ts-mode' which is a major mode +;; for editing PHP files with embedded HTML, JavaScript, CSS and phpdoc. +;; Tree Sitter is used to parse each of these languages. +;; +;; Please note that this package requires `html-ts-mode', which +;; registers itself as the major mode for editing HTML. +;; +;; This package is compatible and has been tested with the following +;; tree-sitter grammars: +;; * https://github.com/tree-sitter/tree-sitter-php +;; * https://github.com/tree-sitter/tree-sitter-html +;; * https://github.com/tree-sitter/tree-sitter-javascript +;; * https://github.com/tree-sitter/tree-sitter-css +;; * https://github.com/claytonrcarter/tree-sitter-phpdoc +;; +;; Features +;; +;; * Indent +;; * IMenu +;; * Navigation +;; * Which-function +;; * Flymake +;; * Tree-sitter parser installation helper +;; * PHP built-in server support +;; * Shell interaction: execute PHP code in a inferior PHP process + +;;; Code: + +(require 'treesit) +(require 'c-ts-common) ;; For comment indent and filling. +(require 'css-mode) ;; for embed css into html +(require 'js) ;; for embed javascript into html +(require 'comint) + +(eval-when-compile + (require 'cl-lib) + (require 'rx) + (require 'subr-x)) + +(declare-function treesit-node-child "treesit.c") +(declare-function treesit-node-child-by-field-name "treesit.c") +(declare-function treesit-node-end "treesit.c") +(declare-function treesit-node-parent "treesit.c") +(declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-string "treesit.c") +(declare-function treesit-node-type "treesit.c") +(declare-function treesit-parser-add-notifier "treesit.c") +(declare-function treesit-parser-buffer "treesit.c") +(declare-function treesit-parser-create "treesit.c") +(declare-function treesit-parser-included-ranges "treesit.c") +(declare-function treesit-parser-list "treesit.c") +(declare-function treesit-parser-language "treesit.c") + +;;; Install treesitter language parsers +(defvar php-ts-mode--language-source-alist + '((php . ("https://github.com/tree-sitter/tree-sitter-php" "v0.22.5")) + (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")) + (css . ("https://github.com/tree-sitter/tree-sitter-css" "v0.21.0"))) + "Treesitter language parsers required by `php-ts-mode'. +You can customize this variable if you want to stick to a specific +commit and/or use different parsers.") + +(defun php-ts-mode-install-parsers () + "Install all the required treesitter parsers. +`php-ts-mode--language-source-alist' defines which parsers to install." + (interactive) + (let ((treesit-language-source-alist php-ts-mode--language-source-alist)) + (dolist (item php-ts-mode--language-source-alist) + (treesit-install-language-grammar (car item))))) + +;;; Custom variables + +(defgroup php-ts-mode nil + "Major mode for editing PHP files." + :prefix "php-ts-mode-" + :group 'languages) + +(defcustom php-ts-mode-indent-offset 4 + "Number of spaces for each indentation step in `php-ts-mode'." + :tag "PHP indent offset" + :version "30.1" + :type 'integer + :safe 'integerp) + +(defcustom php-ts-mode-js-css-indent-offset 2 + "JavaScript and CSS indent spaces related to the