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#74461: [PATCH] Add go-work-ts-mode Date: Sat, 21 Dec 2024 22:10:54 -0500 Message-ID: References: <87ttbzd16p.fsf@disroot.org> <86jzcl81py.fsf@gnu.org> <877c8l55he.fsf@disroot.org> 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="15049"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: dev@rjt.dev, Eli Zaretskii , 74461@debbugs.gnu.org To: Gabriel Santos Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Dec 22 04:12: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 1tPCO9-0003kK-RB for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 22 Dec 2024 04:12:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPCNz-0008JN-Uq; Sat, 21 Dec 2024 22:12:08 -0500 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 1tPCNv-0008Ix-3r for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 22:12:04 -0500 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 1tPCNu-0001b9-LI for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 22:12:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=BS0c28xeF5+QZ/NJ8TDybU4SiV+Biv+hkrWDlZfqIeg=; b=msUkTq2BFQtLDEIy/oYgmkmFzR6NUFZYsquyv1N/RZzfGI7eU/4eiYWVF03fDK0DtpT97H5zdEY1LhdzUx2GkrCH6wN4qzlO3LnQKkCBix38dAn1T4iCscQh8Mo+WENx6e1+l2UTFYqLJmHdEKpw5/rm7DHwKUObRfR14tzGsKJGiq5FqjVAY16PCNbPia7MJs5mgCxEIdRXOkXmAzdKTouk8AAzX7OPebYcAQQf/FnGWDuV2HR1ZFC7jUBKxLt05HVCdIsE5YRUPQITPDKvFjH65iX+XLIGVjd0JU9z6DcB4mGBnjsuzoJMMmYVpE4VqxlRiigYCzwmzVZg8xc4xg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tPCNu-0008Rd-Gp for bug-gnu-emacs@gnu.org; Sat, 21 Dec 2024 22:12:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 22 Dec 2024 03:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74461 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74461-submit@debbugs.gnu.org id=B74461.173483706632384 (code B ref 74461); Sun, 22 Dec 2024 03:12:02 +0000 Original-Received: (at 74461) by debbugs.gnu.org; 22 Dec 2024 03:11:06 +0000 Original-Received: from localhost ([127.0.0.1]:48572 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPCMz-0008QG-Jb for submit@debbugs.gnu.org; Sat, 21 Dec 2024 22:11:05 -0500 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:52000) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPCMw-0008Ph-VF for 74461@debbugs.gnu.org; Sat, 21 Dec 2024 22:11:03 -0500 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 83A0580834; Sat, 21 Dec 2024 22:10:57 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1734837056; bh=sqGQLrsHM/2DP9TIKDw4jNuxRYE2j37Ih+OIilW5A/Q=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=jCJRI08wAHdxl6BZPaRIeYQ583z/5a41SkEG62kSjBSbF63f11dc3jXdC60AuXDW7 PSwr3InYO5G7oSoEvekOKfLJOPE6mYXbJR5OZ85FQ6qulFX8vxydAX8cbKCrloU8nQ Xlq0o2SUX30Lf9Lg4AlcT6KyFrqptboSVBagTMRq+nQp0fGsYqJ9swiaIG+TpS3iT6 rwB2Te6k9zeRK0ft9EJkO8EDosZuszjN/hKhXjrX3xdDRypH6bBQRIOF6paDGM2cnJ CIG34BrhWgU69eGeisemSW9S926YPa6nK0of7v4Py5kt1BBHTN3R6Dys0VUaRdHjx2 J0HsBWXQQ1eYA== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 4EA49804E6; Sat, 21 Dec 2024 22:10:56 -0500 (EST) Original-Received: from asado (unknown [199.119.74.1]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 03BD012025A; Sat, 21 Dec 2024 22:10:55 -0500 (EST) In-Reply-To: <877c8l55he.fsf@disroot.org> (Gabriel Santos's message of "Sat, 30 Nov 2024 08:24:45 -0300") 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:297567 Archived-At: > --- a/lisp/progmodes/eglot.el > +++ b/lisp/progmodes/eglot.el > @@ -273,7 +273,7 @@ automatically)." > (elm-mode . ("elm-language-server")) > (mint-mode . ("mint" "ls")) > ((kotlin-mode kotlin-ts-mode) . ("kotlin-language-server")) > - ((go-mode go-dot-mod-mode go-dot-work-mode go-ts-mode go-mod-ts-mode) > + ((go-mode go-dot-mod-mode go-dot-work-mode go-ts-mode go-mod-ts-mode go-work-ts-mode) > . ("gopls")) > ((R-mode ess-r-mode) . ("R" "--slave" "-e" > "languageserver::run()")) Do we have a way to tell Eglot which LSP server(s) to use via some buffer-local var, instead of having to change this centralized "database"? > @@ -565,6 +568,102 @@ what the parent of the node would be if it were a node." > (if (treesit-ready-p 'gomod) > (add-to-list 'auto-mode-alist '("/go\\.mod\\'" . go-mod-ts-mode))) > > +;; go.work support. I'd use 3 or more semi-colons here, so it acts as a section separator. > +(defvar go-work-ts-mode--syntax-table > + (let ((table (make-syntax-table))) > + (modify-syntax-entry ?/ ". 124b" table) > + (modify-syntax-entry ?\n "> b" table) > + table) > + "Syntax table for `go-work-ts-mode'.") The "4" above is weird since there's no "3". Similarly, the use of "b" is a bit odd since the "normal" comment is unused. > +(defun go-work-ts-mode--in-directive-p () > + "Return non-nil if point is inside a Go workspace directive. This docstring doesn't seem right: the function returns another function, not a boolean. > + (pcase (treesit-node-type (treesit-node-at (point))) > + ("replace" t) > + ("use" t)))))) AKA (member (treesit-node-type (treesit-node-at (point))) '("replace" "use")) > +;;;###autoload > +(define-derived-mode go-work-ts-mode prog-mode "Go Work" > + "Major mode for editing go.work files, powered by tree-sitter." > + :group 'go > + :syntax-table go-work-ts-mode--syntax-table Why not use the standard name for the syntax-table (in which case you don't even need this `:syntax-table` argument)? > + ;; Indent. > + (setq-local indent-tabs-mode t > + treesit-simple-indent-rules go-work-ts-mode--indent-rules) Is this `indent-tabs-mode` setting required by the definition of the go.work syntax/language, or is it a personal preference? If it's a personal preference then it doesn't belong in the major mode, and if it's required by the syntax, then say so in a comment (ideally with a URL pointing to the relevant part of the language definition). > +(if (treesit-ready-p 'gowork) > + (add-to-list 'auto-mode-alist '("/go\\.work\\'" . go-work-ts-mode))) Since we don't have another (non-treesitter) mode for these files, I'd recommend you go straight for: ;;;###autoload (add-to-list 'auto-mode-alist '("/go\\.work\\'" . go-work-ts-mode)) - Stefan