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 19:23:05 +0200 Message-ID: <4927373.OV4Wx5bFTl@fedora> References: <3686989.dWV9SEqChM@3-191.divsi.unimi.it> <3561301.dWV9SEqChM@fedora> <86r0d69q75.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart26490707.1r3eYUQgxm" Content-Transfer-Encoding: 7Bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36813"; 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 20:33:04 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 1sGNLk-0009M5-Fg for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 09 Jun 2024 20:33:04 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sGNLU-000882-70; Sun, 09 Jun 2024 14: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 1sGNLS-00087I-9i for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 14:32: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 1sGNLS-0000y9-0u for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 14:32:46 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sGNLi-0008NB-35 for bug-gnu-emacs@gnu.org; Sun, 09 Jun 2024 14: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: Sun, 09 Jun 2024 18: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.171795792632046 (code B ref 71380); Sun, 09 Jun 2024 18:33:02 +0000 Original-Received: (at 71380) by debbugs.gnu.org; 9 Jun 2024 18:32:06 +0000 Original-Received: from localhost ([127.0.0.1]:53760 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGNKk-0008Kc-9M for submit@debbugs.gnu.org; Sun, 09 Jun 2024 14:32:05 -0400 Original-Received: from mail-ed1-f47.google.com ([209.85.208.47]:55714) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sGNKf-0008Js-5k for 71380@debbugs.gnu.org; Sun, 09 Jun 2024 14:32:00 -0400 Original-Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-57c681dd692so1847296a12.3 for <71380@debbugs.gnu.org>; Sun, 09 Jun 2024 11:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717957835; x=1718562635; 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=BmYOw4T99zy4aNFkrX+Y7MHgRtDCgEqqO6ps/73vsAo=; b=dke5k0LlZQ4j84Igw05vtaXMTbfcdtKdPERKaBOltytLn4IzC66koZV82KuznwD8j1 885OmwFs/jf+7441aW64KkqWSYQS/b0jIqAhhtw070BDe76PspLfKV+7DQ359ZFwrp1F dctnCfAAhXcL/B8IT4iOc31B8kPuHxjCyVkAZ8SFxv58C/xRQGudT157ZW9jzsAGSfyw GB87dvaOKvI0VvwEvTs/5a0z8q2FTO6iG2mqXvczN8sO6QZuFithJ5As00hhYTo35IGN 5r4ybz/0ZWi04L9kPjZIED5kEUHFrAWLhItUQJHftdnwIN4uF4fVeHUSpT/26ijeEPyC 1rsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717957835; x=1718562635; 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=BmYOw4T99zy4aNFkrX+Y7MHgRtDCgEqqO6ps/73vsAo=; b=e9xa4lR6d3u0NaA2Ut5GVX/VHMW6dI4Pgx/RqBgLCNXcAqz3dSso9wRfnulBD2O0Wy iPp9bJelJLgDQJ/XEznzchR3tAdulWcF/7yaYYsJcUtctax83xORgbu4+aP51ozCZp9p NUFwmZxMlTheGozNaqLmCSJ+k/2NwvvcyGJMkFO7DpRNjyitoGfUfBSUs4rt9+SsJL5h 9y2FgVJ6zn8mbB0nr/TmK5txz8q7FcwxwbHAyXJKFtxPkFuGVsKegBT571bRkVh6zYrM ZlqerRbrUT+62TjC9towHMMNvhjlIhcXhBwuxQZO4V8fNYaMV067GPjC5nuQUjb0219G 92tw== X-Gm-Message-State: AOJu0YxFmoXhQ01z6B12yHO0PHXOB8ceKh+F0fGL9684+K8pSly2C97v g1Lhezz2cC8zi8EaDYTroEG90gZ/JccDJdUkeo1Cu57dsg6riR3Xj3xK2g== X-Google-Smtp-Source: AGHT+IH/BQG+3pq8NaPUD9rmJNB47O/l3+QkNZ1laX1nVWVN9irlqYbiLPUVaQBho9KTK2HvtyYzJg== X-Received: by 2002:a2e:a608:0:b0:2eb:de21:94a1 with SMTP id 38308e7fff4ca-2ebde2195ffmr12844931fa.43.1717953787628; Sun, 09 Jun 2024 10:23:07 -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 4fb4d7f45d1cf-57aae2023a1sm5889903a12.61.2024.06.09.10.23.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jun 2024 10:23:07 -0700 (PDT) In-Reply-To: <86r0d69q75.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:286961 Archived-At: This is a multi-part message in MIME format. --nextPart26490707.1r3eYUQgxm Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="utf-8" In data domenica 9 giugno 2024 15:54:38 CEST, Eli Zaretskii ha scritto: > > From: Vincenzo Pupillo > > Cc: 71380@debbugs.gnu.org > > Date: Sat, 08 Jun 2024 13:15:58 +0200 > > > > In data sabato 8 giugno 2024 12:45:08 CEST, Eli Zaretskii ha scritto: > > > > From: Vincenzo Pupillo > > > > Cc: 71380@debbugs.gnu.org > > > > Date: Sat, 08 Jun 2024 11:31:05 +0200 > > > > > > > > this is the patch update. I followed Stefan's advice and removed the > > > > modification of the 'mode-line' and the comment in the > > > > 'php-ts-mode--syntax- table'. > > > > > > 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. 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? Thanks. Vincenzo --nextPart26490707.1r3eYUQgxm 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