unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
@ 2023-02-02 20:37 Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-04  8:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 7+ messages in thread
From: Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-02 20:37 UTC (permalink / raw)
  To: 61238

[-- Attachment #1: Type: text/plain, Size: 1346 bytes --]

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''

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-go-ts-mode-type-switch-and-select-case-blocks-in.patch --]
[-- Type: text/patch, Size: 1638 bytes --]

From b4d6ed0dcb2536d6345e38edd7fc3ae1661d99b7 Mon Sep 17 00:00:00 2001
From: Davide Masserut <dm@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)))
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
  2023-02-02 20:37 bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-02-04  8:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-04 10:15   ` Eli Zaretskii
  2023-02-04 17:21   ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 7+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-04  8:24 UTC (permalink / raw)
  To: Davide Masserut; +Cc: 61238, eliz


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@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)))





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
  2023-02-04  8:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-02-04 10:15   ` Eli Zaretskii
  2023-02-04 10:40     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-04 17:21   ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2023-02-04 10:15 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: 61238, dm

> From: Theodor Thornhill <theo@thornhill.no>
> Cc: 61238@debbugs.gnu.org, eliz@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.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
  2023-02-04 10:15   ` Eli Zaretskii
@ 2023-02-04 10:40     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 7+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-04 10:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 61238, dm

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Theodor Thornhill <theo@thornhill.no>
>> Cc: 61238@debbugs.gnu.org, eliz@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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
  2023-02-04  8:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-04 10:15   ` Eli Zaretskii
@ 2023-02-04 17:21   ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-02-04 18:29     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 7+ messages in thread
From: Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-04 17:21 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: 61238, eliz

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]


Theodor Thornhill <theo@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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fix-go-ts-mode-type-switch-and-select-case-blocks-in.patch --]
[-- Type: text/x-patch, Size: 4465 bytes --]

From 90b0f6ce31e60ca36f8625e8386379259d75c8a0 Mon Sep 17 00:00:00 2001
From: Davide Masserut <dm@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
* test/lisp/progmodes/go-ts-mode-resources/indent.erts: New .erts file
to test indentation of Go constructs and prevent regression of bug
fixes.
* test/lisp/progmodes/go-ts-mode-tests.el: New file with go-ts-mode
tests.
---
 lisp/progmodes/go-ts-mode.el                  |  4 ++
 .../go-ts-mode-resources/indent.erts          | 47 +++++++++++++++++++
 test/lisp/progmodes/go-ts-mode-tests.el       | 31 ++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 test/lisp/progmodes/go-ts-mode-resources/indent.erts
 create mode 100644 test/lisp/progmodes/go-ts-mode-tests.el

diff --git a/lisp/progmodes/go-ts-mode.el b/lisp/progmodes/go-ts-mode.el
index 5f3e1ea3e68..95dcf653fc6 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,7 +83,10 @@ 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 "select_statement") parent-bol 0)
+     ((parent-is "type_case") parent-bol go-ts-mode-indent-offset)
      ((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)
      (no-node parent-bol 0)))
   "Tree-sitter indent rules for `go-ts-mode'.")
diff --git a/test/lisp/progmodes/go-ts-mode-resources/indent.erts b/test/lisp/progmodes/go-ts-mode-resources/indent.erts
new file mode 100644
index 00000000000..a89d69b307c
--- /dev/null
+++ b/test/lisp/progmodes/go-ts-mode-resources/indent.erts
@@ -0,0 +1,47 @@
+Code:
+  (lambda ()
+    (go-ts-mode)
+    (indent-region (point-min) (point-max)))
+
+Point-Char: |
+
+Name: Basic
+
+=-=
+package main
+
+func main() {
+}
+=-=-=
+
+Name: Switch and Select
+
+=-=
+package main
+
+func main() {
+	var x any
+	switch x {
+	case 1:
+		println("one")
+	default:
+		println("default case")
+	}
+
+	switch x.(type) {
+	case int:
+		println("integer")
+	default:
+		println("don't know the type")
+	}
+
+	var c chan int
+	select {
+	case x := <-c:
+		println(x)
+	default:
+		println("no communication")
+	}
+}
+
+=-=-=
diff --git a/test/lisp/progmodes/go-ts-mode-tests.el b/test/lisp/progmodes/go-ts-mode-tests.el
new file mode 100644
index 00000000000..4bfebcbaac0
--- /dev/null
+++ b/test/lisp/progmodes/go-ts-mode-tests.el
@@ -0,0 +1,31 @@
+;;; go-ts-mode-tests.el --- Tests for Tree-sitter-based Go mode         -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2023 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+(require 'ert-x)
+(require 'treesit)
+
+(ert-deftest go-ts-mode-test-indentation ()
+  (skip-unless (treesit-ready-p 'c))
+  (ert-test-erts-file (ert-resource-file "indent.erts")))
+
+(provide 'go-ts-mode-tests)
+;;; go-ts-mode-tests.el ends here
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
  2023-02-04 17:21   ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-02-04 18:29     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-09-10 17:18       ` Stefan Kangas
  0 siblings, 1 reply; 7+ messages in thread
From: Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2023-02-04 18:29 UTC (permalink / raw)
  To: Davide Masserut; +Cc: 61238, eliz

Davide Masserut <dm@mssdvd.com> writes:

> Theodor Thornhill <theo@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





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation
  2023-02-04 18:29     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2023-09-10 17:18       ` Stefan Kangas
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Kangas @ 2023-09-10 17:18 UTC (permalink / raw)
  To: Theodor Thornhill; +Cc: eliz, 61238-done, Davide Masserut

Theodor Thornhill <theo@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.





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-09-10 17:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 20:37 bug#61238: [PATCH] Fix go-ts-mode type switch and select case blocks indentation Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-04  8:24 ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-04 10:15   ` Eli Zaretskii
2023-02-04 10:40     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-04 17:21   ` Davide Masserut via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-04 18:29     ` Theodor Thornhill via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-10 17:18       ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).