From 680dc8cd919ed7846ca165ce0e26705df7e1b585 Mon Sep 17 00:00:00 2001 From: Tony Gong Date: Sat, 4 Jun 2022 14:53:18 -0700 Subject: [PATCH] Golang do not align to open ( or { Changed the indentation behavior such that an extra level of indentation is added after a line containing a ( or { that is not closed on the same line instead of aligning to the unclosed ( or {. This is consistent with how `go fmt` formats source code. Added regression tests. --- rc/filetype/go.kak | 6 ++---- test/indent/go/deindent-generic-closing-brace/in | 6 ++++++ test/indent/go/deindent-generic-closing-brace/out | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/rc/filetype/go.kak b/rc/filetype/go.kak index 13a4ce8d..c32346a9 100644 --- a/rc/filetype/go.kak +++ b/rc/filetype/go.kak @@ -111,10 +111,8 @@ define-command -hidden go-indent-on-new-line %~ execute-keys -draft /\* \*/ } } catch %{ - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } + # indent after lines with an unclosed { or ( + try %< execute-keys -draft [c[({],[)}] \A[({][^\n]*\n[^\n]*\n?\z j > # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # deindent closing brace(s) when after cursor diff --git a/test/indent/go/deindent-generic-closing-brace/in b/test/indent/go/deindent-generic-closing-brace/in index b360ff42..71631915 100644 --- a/test/indent/go/deindent-generic-closing-brace/in +++ b/test/indent/go/deindent-generic-closing-brace/in @@ -47,3 +47,9 @@ a := []int{ someFunction(%( ) ), } + +14 +foobar(baz,%( ) + +15 +foobar{ // some comment%( ) diff --git a/test/indent/go/deindent-generic-closing-brace/out b/test/indent/go/deindent-generic-closing-brace/out index 26d936fe..d36e493b 100644 --- a/test/indent/go/deindent-generic-closing-brace/out +++ b/test/indent/go/deindent-generic-closing-brace/out @@ -63,3 +63,11 @@ a := []int{ ), } + +14 +foobar(baz, + + +15 +foobar{ // some comment +