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.
This commit is contained in:
Tony Gong 2022-06-04 14:53:18 -07:00
parent 039a10a34c
commit 680dc8cd91
3 changed files with 16 additions and 4 deletions

View File

@ -111,10 +111,8 @@ define-command -hidden go-indent-on-new-line %~
execute-keys -draft <a-?> /\* <ret> <a-K>\*/<ret>
}
} catch %{
# indent after lines ending with { or (
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
# align to opening paren of previous line
try %{ execute-keys -draft [( <a-k> \A\([^\n]+\n[^\n]*\n?\z <ret> s \A\(\h*.|.\z <ret> '<a-;>' & }
# indent after lines with an unclosed { or (
try %< execute-keys -draft [c[({],[)}] <ret> <a-k> \A[({][^\n]*\n[^\n]*\n?\z <ret> j<a-gt> >
# indent after a switch's case/default statements
try %[ execute-keys -draft k<a-x> <a-k> ^\h*(case|default).*:$ <ret> j<a-gt> ]
# deindent closing brace(s) when after cursor

View File

@ -47,3 +47,9 @@ a := []int{
someFunction(%( )
),
}
14
foobar(baz,%( )
15
foobar{ // some comment%( )

View File

@ -63,3 +63,11 @@ a := []int{
),
}
14
foobar(baz,
15
foobar{ // some comment