Subject: Re: bug#75362: 29.4; go-ts-mode.el: wrong indentation inside var list
From: Yuan Fu <[email-masked]>
To: Roi Martin <[email-masked]>
Cc: [email-masked]
Date: Sun, 12 Jan 2025 22:35:35 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

> On Jan 4, 2025, at 7:40 AM, 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 Roi, and especially thanks for finding the change in grammar!

The good news is, I just checked and it’s fixed in Emacs 30. Before then, something like this should fix it for you:

(add-hook 'go-ts-mode-hook #'fix-go-ts-mode-indentation)
(defun fix-go-ts-mode-indentation ()
  (setf (alist-get 'go treesit-simple-indent-rules)
        (append (alist-get 'go treesit-simple-indent-rules)
                '(((parent-is "var_spec_list") parent-bol go-ts-mode-indent-offset)))))

Yuan