From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#71380: 30.0.50; Submitting php-ts-mode, new major mode for php Date: Thu, 06 Jun 2024 10:06:21 -0400 Message-ID: References: <3686989.dWV9SEqChM@3-191.divsi.unimi.it> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27102"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 71380@debbugs.gnu.org To: Vincenzo Pupillo Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 06 16:06:57 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 1sFDlY-0006qH-O8 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 06 Jun 2024 16:06:57 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFDlS-00011l-3X; Thu, 06 Jun 2024 10:06:50 -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 1sFDlQ-0000y2-4g for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2024 10:06:48 -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 1sFDlP-00049q-Rx for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2024 10:06:47 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sFDle-0008AP-6N for bug-gnu-emacs@gnu.org; Thu, 06 Jun 2024 10:07:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 06 Jun 2024 14:07: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.171768282031386 (code B ref 71380); Thu, 06 Jun 2024 14:07:02 +0000 Original-Received: (at 71380) by debbugs.gnu.org; 6 Jun 2024 14:07:00 +0000 Original-Received: from localhost ([127.0.0.1]:54171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sFDlc-0008A9-3q for submit@debbugs.gnu.org; Thu, 06 Jun 2024 10:07:00 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:54330) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sFDlX-00089u-Ko for 71380@debbugs.gnu.org; Thu, 06 Jun 2024 10:06:59 -0400 Original-Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 0CF7F440C6D; Thu, 6 Jun 2024 10:06:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1717682793; bh=gIvsFwiZtYkCBvFyFd5DDaSTVWmHXj4TT5A5GFJpcUo=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=lP1bNoxtG1HVHnL92jS/lm8kYlGNT2QtYQYwvnOfHpsGrY/6MCh7kMCrrO5HqVj1Z 5t/Jeqh9qKz9Gwo4jUqzr/fhcCOyuGhWJtqHM4WoVID+xJNfG+yZH2JM8dhOXjr6sT TYFONwufxIl8wsX/MHpId/1a1isz2EkQX2jIkbCVQdiu5BL7kpp521x63qP8vfF9ui BwwlzznneCiIPUsyrVNc4AMzppCbViGyVCIvKfqW3clNFKjlWZMumjzZN3c4gA34+J 7yFtHjWQK3fpfX01/YEu7ud6Kv3Y5U1E6VLZuRHFCnIPzrOQFARMo2tl8eHSGnIh9K c1NClusCQv3tQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 65FBE440C48; Thu, 6 Jun 2024 10:06:33 -0400 (EDT) Original-Received: from pastel (unknown [24.140.236.196]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 424DB1207BB; Thu, 6 Jun 2024 10:06:33 -0400 (EDT) In-Reply-To: <3686989.dWV9SEqChM@3-191.divsi.unimi.it> (Vincenzo Pupillo's message of "Wed, 05 Jun 2024 15:59:20 +0200") 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:286702 Archived-At: I have not read the whole code, but just noticed the things below: > + (named-let loop ((res nil) > + (buffers (buffer-list))) > + (if (null buffers) > + (mapc (lambda (b) > + (with-current-buffer b > + (php-ts-mode-set-style val))) > + res) > + (let ((buffer (car buffers))) > + (with-current-buffer buffer > + (if (derived-mode-p 'php-ts-mode) > + (loop (append res (list buffer)) (cdr buffers)) > + (loop res (cdr buffers)))))))) These `loop` calls are not in tail-position, so this will eat up the stack (because of the surrounding `with-current-buffer`). Also, I don't understand why you do it in such a complicated way. Isn't this better written: (dolist (buffer (buffer-list)) (with-current-buffer buffer (when (derived-mode-p 'php-ts-mode) (php-ts-mode-set-style val)))) ? > +(defcustom php-ts-mode-indent-style 'psr2 > + "Style used for indentation. > +The selected style could be one of: > +`PSR-2/PSR-12' - use PSR standards (PSR-2, PSR-12), thi is the default. > +`PEAR' - use coding styles preferred for PEAR code and modules. > +`Drupal' - use coding styles preferred for working with Drupal projects. > +`WordPress' - use coding styles preferred for working with WordPress projects. > +`Symfony' - use coding styles preferred for working with Symfony projects. > +`Zend' - use coding styles preferred for working with Zend projects. > + > +If one of the supplied styles doesn't suffice, a function could be > +set instead. This function is expected return a list that > +follows the form of `treesit-simple-indent-rules'." > + :tag "PHP indent style" > + :version "30.1" > + :type '(choice (const :tag "PSR-2/PSR-12" psr2) > + (const :tag "PEAR" pear) > + (const :tag "Drupal" drupal) > + (const :tag "WordPress" wordpress) > + (const :tag "Symfony" symfony) > + (const :tag "Zend" zend) > + (function :tag "A function for user customized style" ignore)) > + :set #'php-ts-mode--indent-style-setter > + :safe 'c-ts-indent-style-safep) The :safe arg is also a function, so please #' it as well. > +(defvar php-ts-mode--syntax-table > + (let ((table (make-syntax-table))) > + ;; Taken from the cc-langs version Does this mean it comes from "the cc-mode-based `php-mode.el`" or from `cc-langs.el` (and if so, which part, exactly)? > +;; taken from c-ts-mode [...] > +;; taken from c-ts-mode Are these literal copies? Maybe we should consolidate the code with that of `c-ts-mode` to avoid the code duplication? > + (cond > + ((equal comment-start "/*") (setq-local comment-end "*/")) > + ((equal comment-start "//") (setq-local comment-end "")) > + ((equal comment-start "#") (setq-local comment-end "")) > + ((equal comment-start "/**") (setq-local comment-end "*/"))) > + (setq mode-name (concat "PHP" (string-trim-right comment-start))) > + (force-mode-line-update)) Is `comment-start` important enough to merit being part of the mode name? > +(define-derived-mode php-ts-mode prog-mode "PHP" > + "Major mode for editing PHP, powered by tree-sitter. > + > +\\{php-ts-mode-map}" \\{php-ts-mode-map} is not necessary because `define-derived-mode` adds for you anyway. > +(derived-mode-add-parents 'php-ts-mode '(php-mode)) I'd move it next to the `define-derived-mode`. Stefan