Do not indent Golang comments as code
When indenting on newline in Go files, only remove trailing whitespace on the previous line and copy indentation of the previous line if in comment context. Added regression tests.
This commit is contained in:
parent
6f801c6cda
commit
039a10a34c
|
@ -102,16 +102,24 @@ define-command -hidden go-indent-on-new-line %~
|
|||
evaluate-commands -draft -itersel %=
|
||||
# preserve previous line indent
|
||||
try %{ execute-keys -draft <semicolon>K<a-&> }
|
||||
# indent after lines ending with { or (
|
||||
try %[ execute-keys -draft k<a-x> <a-k> [{(]\h*$ <ret> j<a-gt> ]
|
||||
# cleanup trailing white spaces on the previous line
|
||||
try %{ execute-keys -draft k<a-x> s \h+$ <ret>d }
|
||||
# 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 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
|
||||
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
|
||||
try %{
|
||||
try %{ # line comment
|
||||
execute-keys -draft k<a-x> s ^\h*// <ret>
|
||||
} catch %{ # block comment
|
||||
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 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
|
||||
try %[ execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> ]
|
||||
}
|
||||
=
|
||||
~
|
||||
|
||||
|
|
1
test/indent/go/insert-comment/cmd
Normal file
1
test/indent/go/insert-comment/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>
|
11
test/indent/go/insert-comment/in
Normal file
11
test/indent/go/insert-comment/in
Normal file
|
@ -0,0 +1,11 @@
|
|||
1
|
||||
// foo(bar,%( )
|
||||
|
||||
2
|
||||
// foo(bar,%( )
|
||||
|
||||
3
|
||||
// foo{%( )
|
||||
|
||||
4
|
||||
// foo{%( )
|
15
test/indent/go/insert-comment/out
Normal file
15
test/indent/go/insert-comment/out
Normal file
|
@ -0,0 +1,15 @@
|
|||
1
|
||||
// foo(bar,
|
||||
//
|
||||
|
||||
2
|
||||
// foo(bar,
|
||||
//
|
||||
|
||||
3
|
||||
// foo{
|
||||
//
|
||||
|
||||
4
|
||||
// foo{
|
||||
//
|
4
test/indent/go/insert-comment/rc
Normal file
4
test/indent/go/insert-comment/rc
Normal file
|
@ -0,0 +1,4 @@
|
|||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/go.kak"
|
||||
set buffer filetype go
|
||||
set-option global disabled_hooks go-insert-closing-delimiter
|
Loading…
Reference in New Issue
Block a user