GNU bug report logs - #61238
[PATCH] Fix go-ts-mode type switch and select case blocks indentation

Previous Next

Package: emacs;

Reported by: Davide Masserut <dm <at> mssdvd.com>

Date: Thu, 2 Feb 2023 20:40:01 UTC

Severity: normal

Tags: patch

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 61238 in the body.
You can then email your comments to 61238 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#61238; Package emacs. (Thu, 02 Feb 2023 20:40:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Davide Masserut <dm <at> mssdvd.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Thu, 02 Feb 2023 20:40:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Davide Masserut <dm <at> mssdvd.com>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
Date: Thu, 02 Feb 2023 21:37:06 +0100
[Message part 1 (text/plain, inline)]
Tags: patch

This patch add indentation for Go type switch and select case 
blocks.

Current behavior
```
	var x any
	switch x.(type) {
	case int:
	println(x)
	}

	var c chan int
	select {
	case x := <-c:
	println(x)
	}
```

Correct behavior
```
	var x any
	switch x.(type) {
	case int:
		println(x)
	}

	var c chan int
	select {
	case x := <-c:
		println(x)
	}
```



In GNU Emacs 30.0.50 (build 14, x86_64-pc-linux-gnu, GTK+ Version
3.24.36, cairo version 1.17.6) of 2023-02-02 built on T480s
Repository revision: bfd338aad9d1e6bf898fc19d23e1a5ca4e696316
Repository branch: master
System Description: Arch Linux

Configured using:
'configure --sysconfdir=/etc --prefix=/usr --libexecdir=/usr/lib
--localstatedir=/var --with-pgtk --with-native-compilation
'CFLAGS=-march=native -O2 -pipe -fno-plt -fexceptions
-Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
-fstack-clash-protection -fcf-protection -g
-ffile-prefix-map=/home/davide/src/emacs-mssdvd-git/src=/usr/src/debug/emacs-mssdvd-git'
LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now
'CXXFLAGS=-march=native -O2 -pipe -fno-plt -fexceptions
-Wp,-D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security
-fstack-clash-protection -fcf-protection 
-Wp,-D_GLIBCXX_ASSERTIONS -g
-ffile-prefix-map=/home/davide/src/emacs-mssdvd-git/src=/usr/src/debug/emacs-mssdvd-git''
[0001-Fix-go-ts-mode-type-switch-and-select-case-blocks-in.patch (text/patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61238; Package emacs. (Sat, 04 Feb 2023 08:25:02 GMT) Full text and rfc822 format available.

Message #8 received at 61238 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Davide Masserut <dm <at> mssdvd.com>
Cc: 61238 <at> debbugs.gnu.org, eliz <at> gnu.org
Subject: Re: bug#61238: [PATCH] Fix go-ts-mode type switch and select case
 blocks indentation
Date: Sat, 04 Feb 2023 09:24:08 +0100
Hey there, Davide, and thanks for the clear bug-report!

This looks good to me, but before I install, Maybe you can also add a
test for this, similar to the ones in c-ts-mode-tests.el?

Also, just checking - is fsf assignment needed for this change? Maybe
you've done it already, if so, forgive my ignorance :-)

Theo

> Tags: patch
>
> This patch add indentation for Go type switch and select case blocks.
>
> Current behavior
> ```
> 	var x any
> 	switch x.(type) {
> 	case int:
> 	println(x)
> 	}
>
> 	var c chan int
> 	select {
> 	case x := <-c:
> 	println(x)
> 	}
> ```
>
> Correct behavior
> ```
> 	var x any
> 	switch x.(type) {
> 	case int:
> 		println(x)
> 	}
>
> 	var c chan int
> 	select {
> 	case x := <-c:
> 		println(x)
> 	}
> ```
>
>
>>From b4d6ed0dcb2536d6345e38edd7fc3ae1661d99b7 Mon Sep 17 00:00:00 2001
> From: Davide Masserut <dm <at> mssdvd.com>
> Date: Thu, 2 Feb 2023 21:00:02 +0100
> Subject: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
>
> * lisp/progmodes/go-ts-mode.el (go-ts-mode--indent-rules): Add
> indentation for type switch and select case blocks
> ---
>  lisp/progmodes/go-ts-mode.el | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
> index 5f3e1ea3e68..0270b92445d 100644
> --- a/lisp/progmodes/go-ts-mode.el
> +++ b/lisp/progmodes/go-ts-mode.el
> @@ -72,6 +72,7 @@ go-ts-mode--indent-rules
>       ((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 "communication_case") 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)
> @@ -82,6 +83,7 @@ go-ts-mode--indent-rules
>       ((parent-is "labeled_statement") parent-bol go-ts-mode-indent-offset)
>       ((parent-is "literal_value") parent-bol go-ts-mode-indent-offset)
>       ((parent-is "parameter_list") parent-bol go-ts-mode-indent-offset)
> +     ((parent-is "type_case") 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)))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61238; Package emacs. (Sat, 04 Feb 2023 10:16:02 GMT) Full text and rfc822 format available.

Message #11 received at 61238 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: 61238 <at> debbugs.gnu.org, dm <at> mssdvd.com
Subject: Re: bug#61238: [PATCH] Fix go-ts-mode type switch and select case
 blocks indentation
Date: Sat, 04 Feb 2023 12:15:58 +0200
> From: Theodor Thornhill <theo <at> thornhill.no>
> Cc: 61238 <at> debbugs.gnu.org, eliz <at> gnu.org
> Date: Sat, 04 Feb 2023 09:24:08 +0100
> 
> Also, just checking - is fsf assignment needed for this change? Maybe
> you've done it already, if so, forgive my ignorance :-)

Davide's assignment is already on file, so there's no problem in that
department.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61238; Package emacs. (Sat, 04 Feb 2023 10:41:02 GMT) Full text and rfc822 format available.

Message #14 received at 61238 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 61238 <at> debbugs.gnu.org, dm <at> mssdvd.com
Subject: Re: bug#61238: [PATCH] Fix go-ts-mode type switch and select case
 blocks indentation
Date: Sat, 04 Feb 2023 11:40:12 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Theodor Thornhill <theo <at> thornhill.no>
>> Cc: 61238 <at> debbugs.gnu.org, eliz <at> gnu.org
>> Date: Sat, 04 Feb 2023 09:24:08 +0100
>> 
>> Also, just checking - is fsf assignment needed for this change? Maybe
>> you've done it already, if so, forgive my ignorance :-)
>
> Davide's assignment is already on file, so there's no problem in that
> department.

Great :-)

Theo




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61238; Package emacs. (Sat, 04 Feb 2023 17:30:03 GMT) Full text and rfc822 format available.

Message #17 received at 61238 <at> debbugs.gnu.org (full text, mbox):

From: Davide Masserut <dm <at> mssdvd.com>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: 61238 <at> debbugs.gnu.org, eliz <at> gnu.org
Subject: Re: bug#61238: [PATCH] Fix go-ts-mode type switch and select case
 blocks indentation
Date: Sat, 04 Feb 2023 18:21:09 +0100
[Message part 1 (text/plain, inline)]
Theodor Thornhill <theo <at> thornhill.no> writes:

> Hey there, Davide, and thanks for the clear bug-report!
>
> This looks good to me, but before I install, Maybe you can also 
> add a
> test for this, similar to the ones in c-ts-mode-tests.el?
>
> Also, just checking - is fsf assignment needed for this change? 
> Maybe
> you've done it already, if so, forgive my ignorance :-)
>
> Theo

I added the tests and also indentation rules for the "case" and 
"default" keywords so that they are aligned with their parent.

[0001-Fix-go-ts-mode-type-switch-and-select-case-blocks-in.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#61238; Package emacs. (Sat, 04 Feb 2023 18:30:02 GMT) Full text and rfc822 format available.

Message #20 received at 61238 <at> debbugs.gnu.org (full text, mbox):

From: Theodor Thornhill <theo <at> thornhill.no>
To: Davide Masserut <dm <at> mssdvd.com>
Cc: 61238 <at> debbugs.gnu.org, eliz <at> gnu.org
Subject: Re: bug#61238: [PATCH] Fix go-ts-mode type switch and select case
 blocks indentation
Date: Sat, 04 Feb 2023 19:29:50 +0100
Davide Masserut <dm <at> mssdvd.com> writes:

> Theodor Thornhill <theo <at> thornhill.no> writes:
>
>> Hey there, Davide, and thanks for the clear bug-report!
>>
>> This looks good to me, but before I install, Maybe you can also 
>> add a
>> test for this, similar to the ones in c-ts-mode-tests.el?
>>
>> Also, just checking - is fsf assignment needed for this change? 
>> Maybe
>> you've done it already, if so, forgive my ignorance :-)
>>
>> Theo

Thanks! I've commited and pushed this to the emacs-29 branch.  I made a
small tweak to the commit message and fixed this:

(ert-deftest go-ts-mode-test-indentation ()
  (skip-unless (treesit-ready-p 'c))
  (ert-test-erts-file (ert-resource-file "indent.erts")))

Thanks again,

Theo




Reply sent to Stefan Kangas <stefankangas <at> gmail.com>:
You have taken responsibility. (Sun, 10 Sep 2023 17:19:02 GMT) Full text and rfc822 format available.

Notification sent to Davide Masserut <dm <at> mssdvd.com>:
bug acknowledged by developer. (Sun, 10 Sep 2023 17:19:02 GMT) Full text and rfc822 format available.

Message #25 received at 61238-done <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Theodor Thornhill <theo <at> thornhill.no>
Cc: eliz <at> gnu.org, 61238-done <at> debbugs.gnu.org, Davide Masserut <dm <at> mssdvd.com>
Subject: Re: bug#61238: [PATCH] Fix go-ts-mode type switch and select case
 blocks indentation
Date: Sun, 10 Sep 2023 10:18:34 -0700
Theodor Thornhill <theo <at> thornhill.no> writes:

> Thanks! I've commited and pushed this to the emacs-29 branch.  I made a
> small tweak to the commit message and fixed this:
>
> (ert-deftest go-ts-mode-test-indentation ()
>   (skip-unless (treesit-ready-p 'c))
>   (ert-test-erts-file (ert-resource-file "indent.erts")))

It seems like this issue was fixed, but it was left open in the bug
tracker.  I'm therefore closing it now.

Please remember to close bug reports when they are fixed.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 09 Oct 2023 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 193 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.