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 21:37:40 +0200 Message-ID: <5638447.rdbgypaU67@fedora> References: <3686989.dWV9SEqChM@3-191.divsi.unimi.it> <4927373.OV4Wx5bFTl@fedora> <86le3e9fbv.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3524281.LZWGnKmheA" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39088"; 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 21:56:18 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 1sGOeG-000A0D-GS for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Jun 2024 21:56:16 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGOdn-0005gE-Te; Sun, 09 Jun 2024 15:55:47 -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 1sGOdl-0005f3-Rr for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 15:55:45 -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 1sGOdl-0007jw-JA for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 15:55:45 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sGOe1-0003df-PU for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 15:56:01 -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 19:56:01 +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.171796292613905 (code B ref 71380); Sun, 09 Jun 2024 19:56:01 +0000 Original-Received: (at 71380) by debbugs.gnu.org; 9 Jun 2024 19:55:26 +0000 Original-Received: from localhost ([127.0.0.1]:57705 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGOdO-0003c5-Nw for submit@debbugs.gnu.org; Sun, 09 Jun 2024 15:55:26 -0400 Original-Received: from mail-lf1-f53.google.com ([209.85.167.53]:51534) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGOUb-0003F9-Tb for 71380@debbugs.gnu.org; Sun, 09 Jun 2024 15:46:21 -0400 Original-Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-52bc3130ae6so2131339e87.3 for <71380@debbugs.gnu.org>; Sun, 09 Jun 2024 12:46:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717962295; x=1718567095; 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=zT4jkQ6utBsPFexuNFQ1lgY3wT+POZIb1MhoK5m+J70=; b=VV0U3JP6fXZytVGNkd5rny/5qJmRTIhJ1goZ8n8RTwjK7WqjgpEvNSTGO5ruWtYnaS HAmukl+K4tA+Ktv1LxbzZ2uV6BNyJeYno3B6XOiLqpk4KHCCzmYRZhaifv+gV9rKmF8z HA7MQjUolnfUUxYj8kHiTdjRvxgJM2K7BjcBVtHCtBGgB+/rTinQHweNfQfmekAhaJey JcY6kj54shTkANkzyMaefYuTvQcqmczWDdKnPOZEqtX5E12MfCDgsYqpZx1w7dsGYdIP cm+UEo+jgGyqvu1UHXHYniotODZ2Ler+vMTLYx+7mU6ZfGxlHdiNYXAPEY2ZjMklX5Ry 80tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717962295; x=1718567095; 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=zT4jkQ6utBsPFexuNFQ1lgY3wT+POZIb1MhoK5m+J70=; b=l9zssgOG/5WFac0iYcLZyEZIV8NjDC2WIvXaBshK3ubvnsjqnZyTmI2n2KsNwQWwiF n//3WDZy5MmollQna1S1/2IqcgogqMPZeQ9ggLd/F31MuMqo5/rUIKH3+662nhvjH1Xa +nCCkuzpsfFQugD68VFFHC//CY+1/YllGYbuuaRPjBakyWmzrDs/GsqSr06iew+Oxb2z 5dkA2dCGJk4q1ktRGc9QmA1Ha9Xcx9tqQclGcrPdBGdgZ+xhQs1U9Hfa7+jhbTrTcgpx 72l98R6o34pHpUN5TZOC0rKLaGjzTFbYOIBL6WoCqYIg84vWexpX/HuZauCMq5KPjB9D U7QA== X-Gm-Message-State: AOJu0YzO4pLVSGgr9s/KC1P4ycrCfo8i+fKsE2zSW30cKPDLrxi4o7IX FvzBqDD3EpPwv9dtNTX6bij5NE32o6dwb/STpecwlLIkHnS+eOobAj7jHQ== X-Google-Smtp-Source: AGHT+IHuSJxWVVLSZmXXKRcya34WUlamSSVyipn5krFQVt0+lSJ1A+0hQWMYJUgiJFSyXo0OhGbdPQ== X-Received: by 2002:a17:906:7f06:b0:a6f:1e06:29ba with SMTP id a640c23a62f3a-a6f1e0638b8mr70674766b.65.1717961862006; Sun, 09 Jun 2024 12:37:42 -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 a640c23a62f3a-a6f1f45e306sm50363766b.183.2024.06.09.12.37.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 12:37:41 -0700 (PDT) In-Reply-To: <86le3e9fbv.fsf@gnu.org> 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:286971 Archived-At: This is a multi-part message in MIME format. --nextPart3524281.LZWGnKmheA Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" 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 --nextPart3524281.LZWGnKmheA 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 230f3f6da0e3d46ba6b83f71c545d7f1c2cbac16 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 | 1642 +++++++++++++++++++++++++++++++++ 2 files changed, 1647 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..da3f039eb32 =2D-- /dev/null +++ b/lisp/progmodes/php-ts-mode.el @@ -0,0 +1,1642 @@ +;;; 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 '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