From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Theodor Thornhill via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#60025: [PATCH] Add go-ts-mode and go-mod-ts-mode Date: Thu, 15 Dec 2022 08:20:46 +0100 Message-ID: <87y1r9w2sx.fsf@thornhill.no> References: <83r0x3pk28.fsf@gnu.org> <83edt2nqgm.fsf@gnu.org> <5HEX4A0JH8fd_VGG1FbzJ8QtBZXlHLKtuAGgc_TUHvzKCzU2Q3PYbbi3rUWeLOBoJzg0qsQgVhwGZCF86A2Xg--I2ep5d1KjKoUoHrxXpqA=@rjt.dev> <87zgbpznfa.fsf@thornhill.no> <7fPZo7wRGoWPnr5djOSL0gsOE-Q15-l2y-INvJ7z5QXOpXmV_ct4soqgJTYtHZ6EReO3ROGRS_VYnKkYNH6j1CghKfMbRXMmanEB-eaANjk=@rjt.dev> Reply-To: Theodor Thornhill Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8808"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Yuan Fu , Eli Zaretskii , 60025@debbugs.gnu.org To: Randy Taylor Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 15 08:21:36 2022 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 1p5iYg-00023X-42 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Dec 2022 08:21:34 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p5iYK-0000QI-J4; Thu, 15 Dec 2022 02:21:12 -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 1p5iYB-0000Pl-Am for bug-gnu-emacs@gnu.org; Thu, 15 Dec 2022 02:21:07 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5iYA-0003J3-TS for bug-gnu-emacs@gnu.org; Thu, 15 Dec 2022 02:21:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p5iYA-0007Z0-2j for bug-gnu-emacs@gnu.org; Thu, 15 Dec 2022 02:21:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Theodor Thornhill Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Dec 2022 07:21:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 60025 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 60025-submit@debbugs.gnu.org id=B60025.167108885329059 (code B ref 60025); Thu, 15 Dec 2022 07:21:02 +0000 Original-Received: (at 60025) by debbugs.gnu.org; 15 Dec 2022 07:20:53 +0000 Original-Received: from localhost ([127.0.0.1]:42433 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p5iY0-0007Yd-R3 for submit@debbugs.gnu.org; Thu, 15 Dec 2022 02:20:53 -0500 Original-Received: from out-203.mta0.migadu.com ([91.218.175.203]:21174) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p5iXx-0007YW-QV for 60025@debbugs.gnu.org; Thu, 15 Dec 2022 02:20:51 -0500 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=thornhill.no; s=key1; t=1671088848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Y2a/FmIAUa6gYE8+ohMtGU215o0BPSo54IsHw2gPH1I=; b=XTXqqkRm4c8sDciOw2oWbMNZ5cVHg/vXyZYx50XygHemhBSQxlM2XsiKkUKf14U5Uf3SWk bn7tjh8C7sTZB/yZxjAEnI2Qj/DttwMNAlr9ifdTKPELKXABvtt7ctdx8mHM24lO6/Xmj1 0BW3MLf18b9aaPhxVBGVwej/+jQnIaWNb9YN5/Jy5qDNuqVnLgGG60cOaoeXejrm5KR3eZ dJWRFzlyc2wlvrVtJOV76cH7augnZ6oBN/7kr3ZlJp3XRn6umQ4TO+fVx4X5lQbD2akXwP o28hnqMZ9BSKFYBxf4Ap24OWIoQ2c+P6bhG8gbF/My6KlCjI3XkQ1MNEX4aiVA== In-Reply-To: <7fPZo7wRGoWPnr5djOSL0gsOE-Q15-l2y-INvJ7z5QXOpXmV_ct4soqgJTYtHZ6EReO3ROGRS_VYnKkYNH6j1CghKfMbRXMmanEB-eaANjk=@rjt.dev> X-Migadu-Flow: FLOW_OUT 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:251025 Archived-At: Randy Taylor writes: > On Wednesday, December 14th, 2022 at 16:27, Theodor Thornhill wrote: >> >> Yeah, I seem to remember seeing these \n nodes in the go-mode I made >> some time ago. There is no node there, so no-node is the rule that >> matches, as there is no parent. I believe you can solve it with >> something like >> >> >> (defun go-backward-up-list () >> (lambda (node parent bol &rest _) >> (save-excursion >> (backward-up-list 1 nil t) >> (back-to-indentation) >> (point)))) >> >> and use some variant of that. Now you can find a different node without >> relying on there being a node where you start. > > Thanks Theo, that worked perfectly. We should consider adding > something like this to the documentation somewhere, since I didn't see > anything like this anywhere (although maybe I missed it). I'm glad! Could be part of a tips and tricks or something? [...] > +(defvar go-ts-mode--indent-rules > + `((go > + ((node-is ")") parent-bol 0) > + ((node-is "]") parent-bol 0) > + ((node-is "}") parent-bol 0) > + ((node-is "labeled_statement") no-indent) > + ((parent-is "argument_list") parent-bol go-ts-mode-indent-offset) > + ((parent-is "block") parent-bol go-ts-mode-indent-offset) > + ((parent-is "const_declaration") parent-bol go-ts-mode-indent-offset) > + ((parent-is "default_case") parent-bol go-ts-mode-indent-offset) > + ((parent-is "expression_case") parent-bol go-ts-mode-indent-offset) > + ((parent-is "expression_switch_statement") parent-bol 0) > + ((parent-is "field_declaration_list") parent-bol go-ts-mode-indent-offset) > + ((parent-is "import_spec_list") parent-bol go-ts-mode-indent-offset) > + ((parent-is "labeled_statement") parent-bol go-ts-mode-indent-offset) > + ((parent-is "literal_value") parent-bol go-ts-mode-indent-offset) > + ((parent-is "type_spec") parent-bol go-ts-mode-indent-offset) > + ((parent-is "var_declaration") parent-bol go-ts-mode-indent-offset) > + (no-node parent-bol 0))) > + "Tree-sitter indent rules for `go-ts-mode'.") No rules for comment? [...] > +;; go.mod support. > + > +(defvar go-mod-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-mod-ts-mode'.") > + > +(defvar go-mod-ts-mode--indent-rules > + `((gomod > + ((node-is ")") parent-bol 0) > + ((parent-is "exclude_directive") parent-bol go-ts-mode-indent-offset) > + ((parent-is "module_directive") parent-bol go-ts-mode-indent-offset) > + ((parent-is "replace_directive") parent-bol go-ts-mode-indent-offset) > + ((parent-is "require_directive") parent-bol go-ts-mode-indent-offset) > + ((parent-is "retract_directive") parent-bol go-ts-mode-indent-offset) > + ((go-mod-ts-mode--in-directive-p) no-indent go-ts-mode-indent-offset) > + (no-node no-indent 0))) > + "Tree-sitter indent rules for `go-mod-ts-mode'.") No rules for comment here either? Theo