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: Sun, 09 Jun 2024 22:36:35 +0200 Message-ID: <4710860.vXUDI8C0e8@fedora> References: <3686989.dWV9SEqChM@3-191.divsi.unimi.it> <86le3e9fbv.fsf@gnu.org> <5638447.rdbgypaU67@fedora> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart2138224.9o76ZdvQCi" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29888"; 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 Sun Jun 09 23:41:21 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 1sGQHv-0007YM-KF for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Jun 2024 23:41:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGQHO-0007zr-R6; Sun, 09 Jun 2024 17:40:46 -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 1sGQHO-0007zd-6S for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 17:40:46 -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 1sGQHN-0002zY-TG for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 17:40:45 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sGQHe-0000KY-F1 for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 17:41: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: Sun, 09 Jun 2024 21:41: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.17179692291121 (code B ref 71380); Sun, 09 Jun 2024 21:41:02 +0000 Original-Received: (at 71380) by debbugs.gnu.org; 9 Jun 2024 21:40:29 +0000 Original-Received: from localhost ([127.0.0.1]:34431 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGQH3-0000Hl-Qd for submit@debbugs.gnu.org; Sun, 09 Jun 2024 17:40:29 -0400 Original-Received: from mail-wm1-f48.google.com ([209.85.128.48]:49503) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGPh6-0003sF-9e for 71380@debbugs.gnu.org; Sun, 09 Jun 2024 17:03:20 -0400 Original-Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-421f4d1c057so161855e9.3 for <71380@debbugs.gnu.org>; Sun, 09 Jun 2024 14:02:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717966914; x=1718571714; 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=V8zIQLEIc09a+WpnvcxmzXZNFhMhgWqOSfrVCz14tgs=; b=YTy9XTcI6t7TJVlVsesm9R0eBv3lEV8n6UfU6TilS+bPw+778gFcCfLCz1+dxgmlK+ zu8Qcd1hAAHUPwNyeLucz3GB+A5QwQZiCyUqZmYk/0+rsupJ9L0hEBiTrUaUJfXdig8M uykdpWHKFcpiPXCkaGN5l5wcACyUV/+ejs3djQgSAbymNW/N3evgEryazznjGHeH/twb PAevMlsnKmIks0rHLIz4eEHFYE5QY516OTujEpirkYELKLpN48i8SEPHs5IzfeDCHOZB j8RQLpt57/1fwBimL1WrvOKbtGh3GmEPfbMVXteC8S74h08HGZdo7hwpjhLz7WT2a2Er arow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717966914; x=1718571714; 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=V8zIQLEIc09a+WpnvcxmzXZNFhMhgWqOSfrVCz14tgs=; b=NerW2eohaRccekl7njmRMWYT1Ve1r5MEYdj49/+HPLtbHRJiGp/RDzmD1uJzJxZWXi a5ir+R2t0B7HWU45esaDYbcksnorDHDmN46gP8An/gEyJ4733Y9FD6WjXAxrps4d+7+z 6ZTBQxbPjqSCC2wMt3w2Dkzco8fpPEGRvYRi3NJO0udVh6TCnr56b0WcBDRSXRav0UuG LUcr6/RM6M6JLV1sqwWrEQYr5CHEb/pMubSzwdPqU5cRycsKAMac/1F4o0db0W5NrArw VcaFwQQ0478Yons7fAcE0yRqwL+WEtLyPv2Gx9+ZX4rolP1z2+xQpheya9fFHqThWa/w ltWg== X-Gm-Message-State: AOJu0YyAZNNwtdM/lX88FlcdE8VFS6CTLsjQqXVqXNKOvdDBXobUTYi1 azORW1yQcKjhtwzBAPeho5gyZsMnGjMG4hl9JsX39weSOFs4CXwIAX4xSg== X-Google-Smtp-Source: AGHT+IHFX7P560H7gUTRdyrTJ2+L6sbjAkDeT42KcBFKtI7uYwsM00dgp7GvgPFD1d+zCJrS8KTCEA== X-Received: by 2002:a05:600c:45c9:b0:421:8e64:5f36 with SMTP id 5b1f17b1804b1-4218e646de0mr14551135e9.14.1717965396840; Sun, 09 Jun 2024 13:36:36 -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-42178c50012sm70148545e9.45.2024.06.09.13.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 13:36:36 -0700 (PDT) In-Reply-To: <5638447.rdbgypaU67@fedora> 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:286986 Archived-At: This is a multi-part message in MIME format. --nextPart2138224.9o76ZdvQCi Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" 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 --nextPart2138224.9o76ZdvQCi 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 23bbaacd3f904349aa4ae81d45f1bfdb1ddbff41 Mon Sep 17 00:00:00 2001 =46rom: Vincenzo Pupillo Date: Sun, 9 Jun 2024 19:04:13 +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 | 1645 +++++++++++++++++++++++++++++++++ 2 files changed, 1650 insertions(+) create mode 100644 lisp/progmodes/php-ts-mode.el diff --git a/etc/NEWS b/etc/NEWS index 60df9760aa4..a30b0744a9c 100644 =2D-- a/etc/NEWS +++ b/etc/NEWS @@ -1967,6 +1967,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..8d28f910416 =2D-- /dev/null +++ b/lisp/progmodes/php-ts-mode.el @@ -0,0 +1,1645 @@ +;;; 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. +;; +;; 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