Subject: bug#75362: 29.4; go-ts-mode.el: wrong indentation inside var list

From: Randy Taylor <[email-masked]>
Date: Sun, 05 Jan 2025 22:05:09 +0000

On Saturday, January 4th, 2025 at 10:40, Roi Martin <[email-masked]> wrote:
> 
> When using the Go tree-sitter grammar v0.23.4 from
> https://github.com/tree-sitter/tree-sitter-go.git, indentation inside
> var lists does not work correctly.
> 
> For instance, the following code is indented as:
> 
> `var ( one = 1 )`
> 
> Instead of:
> 
> `var ( one = 1 )`
> 
> Just in case it can help, I think this stopped working with grammar
> version `v0.21.1`, that introduced `var_spec_list`:
> 
> https://github.com/tree-sitter/tree-sitter-go/compare/v0.21.0...v0.21.1
> 
> Please, take it with a pinch of salt because I'm not very familiar with
> tree-sitter.
> 
> [...]
> 

Thanks for the report.

The attached patch fixes it for me.

From ecb80b849c3bc490085a4146b8f8d499949220c2 Mon Sep 17 00:00:00 2001
From: Randy Taylor <[email-masked]>
Date: Sun, 5 Jan 2025 16:48:00 -0500
Subject: [PATCH] Fix go-ts-mode var spec indentation (Bug#75362)

v0.21.1 and onwards changed how this was indented.

* lisp/progmodes/go-ts-mode.el (go-ts-mode--indent-rules):
Add rule for var_spec_list.
---
 lisp/progmodes/go-ts-mode.el | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 747bf9a9da8..ccfdcb909e5 100644
--- a/lisp/progmodes/go-ts-mode.el
+++ b/lisp/progmodes/go-ts-mode.el
@@ -106,6 +106,7 @@ go-ts-mode--indent-rules
      ((parent-is "type_spec") parent-bol go-ts-mode-indent-offset)
      ((parent-is "type_switch_statement") parent-bol 0)
      ((parent-is "var_declaration") parent-bol go-ts-mode-indent-offset)
+     ((parent-is "var_spec_list") parent-bol go-ts-mode-indent-offset)
      (no-node parent-bol 0)))
   "Tree-sitter indent rules for `go-ts-mode'.")
 
-- 
2.47.1