Improve '}' auto inserting for go language.

Adding "} else if ... {" was not correctly handled.
This commit is contained in:
Michał Kruszewski 2020-09-18 15:06:23 +02:00
parent dbd7e4da79
commit f78cd6daf8
3 changed files with 15 additions and 2 deletions

View File

@ -134,7 +134,7 @@ define-command -hidden go-insert-on-new-line %[
try %[ execute-keys -draft k<a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[
# Validate previous line and that it is not closed yet.
execute-keys -draft k<a-x> <a-k>^<c-r>x.*\{\h*\(?\h*$<ret> J}iJ<a-x> <a-K>^<c-r>x(\)?\h*\})$<ret>
execute-keys -draft k<a-x> <a-k>^<c-r>x.*\{\h*\(?\h*$<ret> j}iJ<a-x> <a-K>^<c-r>x\)?\h*\}<ret>
# Insert closing '}'.
execute-keys -draft o<c-r>x}<esc>
# Delete trailing '}' on the line below the '{'.
@ -148,7 +148,7 @@ define-command -hidden go-insert-on-new-line %[
try %[ execute-keys -draft k<a-x>s^\h+<ret>"xy ] catch %[ reg x '' ]
try %[
# Validate previous line and that it is not closed yet.
execute-keys -draft k<a-x> <a-k>^<c-r>x.*\(\h*$<ret> J}iJ<a-x> <a-K>^<c-r>x(\)\h*\}?)$<ret>
execute-keys -draft k<a-x> <a-k>^<c-r>x.*\(\h*$<ret> J}iJ<a-x> <a-K>^<c-r>x\)<ret>
# Insert closing ')'.
execute-keys -draft o<c-r>x)<esc>
# Delete trailing ')' on the line below the '('.

View File

@ -41,3 +41,9 @@
12
{(
bar()%( ))}
13
a := []int{
someFunction(%( )
),
}

View File

@ -56,3 +56,10 @@
{(
bar()
)}
13
a := []int{
someFunction(
),
}