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: Sat, 08 Jun 2024 11:31:05 +0200 Message-ID: <26432979.1r3eYUQgxm@fedora> References: <3686989.dWV9SEqChM@3-191.divsi.unimi.it> <8634pog94j.fsf@gnu.org> <1872971.LH7GnMWURc@3-191.divsi.unimi.it> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2262030.vFx2qVVIhK" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28887"; 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 Sat Jun 08 11:33:09 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 1sFsRh-0007HI-6b for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 08 Jun 2024 11:33:09 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFsRM-0003PF-Hm; Sat, 08 Jun 2024 05:32:48 -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 1sFsRL-0003Oi-5x for bug-gnu-emacs@gnu.org; Sat, 08 Jun 2024 05:32:47 -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 1sFsRK-0000ut-UC for bug-gnu-emacs@gnu.org; Sat, 08 Jun 2024 05:32:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sFsRa-0000RO-If for bug-gnu-emacs@gnu.org; Sat, 08 Jun 2024 05:33: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, 08 Jun 2024 09:33:02 +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.17178391581613 (code B ref 71380); Sat, 08 Jun 2024 09:33:02 +0000 Original-Received: (at 71380) by debbugs.gnu.org; 8 Jun 2024 09:32:38 +0000 Original-Received: from localhost ([127.0.0.1]:34317 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sFsR8-0000Pi-Lf for submit@debbugs.gnu.org; Sat, 08 Jun 2024 05:32:38 -0400 Original-Received: from mail-lj1-f177.google.com ([209.85.208.177]:48495) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sFsR3-0000P7-1G for 71380@debbugs.gnu.org; Sat, 08 Jun 2024 05:32:33 -0400 Original-Received: by mail-lj1-f177.google.com with SMTP id 38308e7fff4ca-2eaad2c670aso30292401fa.1 for <71380@debbugs.gnu.org>; Sat, 08 Jun 2024 02:32:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717839067; x=1718443867; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LY4pPWChvOOAm4OWTz6QNNfu6Bxk5PLao9A/ntGbvkg=; b=cPlikXX7iwbviojv5aCtbTYvnLcwYnP6jTGjfLjRAT6tWn5hIcP8Xu5+oCHAMBJdLQ Exw8rEfEPTDNdlY4CQ4+zuUo6kIdOzZ3EkTWvnVoqNIGsGVJKaphOjr/1IF2rUxAMczl pAoGpDiuHO41NB4LNtJ9c9XdMcaean7T1XL0NKJylqvKw2kciS5ngPpxkAj//aqpjcTm /98ccMb46b2tLWY3B/pNBNcemXw/Xa4XCJvKw7+oDEMfFLbkz2GCjVhpyf3O+4GOrRLw jo121kFlpxEmSMSMlsSEPLTwZ9HEtYxNm5wg47fU9JLsGsiP2d76qzcaNv7JGoJM8/9H pwhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717839067; x=1718443867; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LY4pPWChvOOAm4OWTz6QNNfu6Bxk5PLao9A/ntGbvkg=; b=UkRdTB6PyBxaVE3Xoi5ZTqNy0gTxC7ccpW5uneRAU8x9rxf03svU2DlZ6ZlbCAg3nK bvrPE94ni3knhoSIYWOq+9vO5puhDUrXWd5+wH4rSIQ1wrOaQOd1i+dcEOi1v55eDuUQ Pa45yaubWrPl6gP6RxAi+NUKgJGpd5gGPlf/Z5fUJJ9F3+pPlDsPIcKc7GovVqa8O7Ok HpaN7UTexVNuO0s+t0cbufmqdJl2cCe3uB5vGiaAqAm69CTRQWviugieDkaIQN0JGjTr jcSkSS0/cWJ1EobaDDaK1JwQh6WiZzEtb/MuAG5p2J0SlOQsEkHIoa2gdXNi4wnpMtke /GcA== X-Gm-Message-State: AOJu0YwX8WRtyBmTQY0uFVTP8x/10nG8rD9u3UhrMxGycGrDfHOsqX/l kui+8I8ijud9L6oL0mgjN0ZzvbihXOQ/urRYbY6O0Ga3X4oMDdB9tQ7ziA== X-Google-Smtp-Source: AGHT+IHjLVKhjwTUoFQEE+8awKHFJtFxPne43Z84wH/flv7gmBpyEqPKUQ6GDK2tZpN8WRYtfneAiw== X-Received: by 2002:a05:651c:4d1:b0:2e0:752c:1f2e with SMTP id 38308e7fff4ca-2eadce1bd83mr35469971fa.1.1717839066858; Sat, 08 Jun 2024 02:31:06 -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 5b1f17b1804b1-4215c1aa30esm77893855e9.13.2024.06.08.02.31.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jun 2024 02:31:06 -0700 (PDT) In-Reply-To: <1872971.LH7GnMWURc@3-191.divsi.unimi.it> 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:286822 Archived-At: This is a multi-part message in MIME format. --nextPart2262030.vFx2qVVIhK Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hi Eli,=20 this is the patch update. I followed Stefan's advice and removed the=20 modification of the 'mode-line' and the comment in the 'php-ts-mode--syntax- table'.=20 Thanks! Vincenzo In data venerd=C3=AC 7 giugno 2024 17:05:58 CEST, Vincenzo Pupillo ha scrit= to: > In data venerd=C3=AC 7 giugno 2024 15:44:44 CEST, Eli Zaretskii ha scritt= o: > > > From: Vincenzo Pupillo > > > Cc: 71380@debbugs.gnu.org > > > Date: Fri, 07 Jun 2024 14:50:24 +0200 > > >=20 > > > In data venerd=C3=AC 7 giugno 2024 13:12:25 CEST, Eli Zaretskii ha sc= ritto: > > > > > > > +(defun php-ts-mode--array-element-heuristic (node parent bol > > > > > > > &rest _) > > > > > > > + "Return of the position of the first element of the array. > > > > > >=20 > > > > > > The "of" part should be deleted here, I think. > > > > >=20 > > > > > I'm not sure how to explain it. Different indentation styles inde= nt > > > > > the > > > > > elements of an array differently when written on multiple rows. F= or > > > > > example. in PSR2 it is like this: > > > > > $a =3D array("a" =3D> 1, > > > > >=20 > > > > > "b" =3D> 2, > > > > > "c" =3D> 3); > > > > >=20 > > > > > while with Zend it is like this: > > > > > $a =3D array("a" =3D> 1, > > > > >=20 > > > > > "b" =3D> 2, > > > > > "c" =3D> 3); > > > > >=20 > > > > > What do you suggest? > > > >=20 > > > > What does the function return in each of these two cases? > > >=20 > > > If '$a =3D array(' is on the same line as '=E2=80=9Ca=E2=80=9D =3D> 1= ,' it returns the > > > initial position of '=E2=80=9Ca=E2=80=9D, otherwise the starting posi= tion of 'array(', > > > like PSR2. > > > In terms of tree-sitter-php the first case is: > > > (treesit-node-start (treesit-node-child parent 2)) > > > while the second is: parent indentation + offset. > >=20 > > Does it return a buffer position or a column? You seem to say that > > sometimes it returns the former and sometimes the latter. >=20 > The point in both cases. >=20 > Vincenzo --nextPart2262030.vFx2qVVIhK 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 8830b49bb5a654ceff9d07cd30bd67c3e498b37e 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 | 1634 +++++++++++++++++++++++++++++++++ 2 files changed, 1639 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..ce36208ac66 =2D-- /dev/null +++ b/lisp/progmodes/php-ts-mode.el @@ -0,0 +1,1634 @@ +;;; php-ts-mode.el --- Major mode PHP using tree-sitter -*- lexical-bindin= g: 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. +;; +;; 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 'html-ts-mode) ;; For embed html +(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 html-ts-mode-indent-offset + "JavaScript and CSS indent spaces related to the