diff --git a/rc/filetype/go.kak b/rc/filetype/go.kak index 9df7f12c..13a4ce8d 100644 --- a/rc/filetype/go.kak +++ b/rc/filetype/go.kak @@ -102,16 +102,24 @@ define-command -hidden go-indent-on-new-line %~ evaluate-commands -draft -itersel %= # preserve previous line indent try %{ execute-keys -draft K } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] # cleanup trailing white spaces on the previous line try %{ execute-keys -draft k s \h+$ d } - # align to opening paren of previous line - try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } - # indent after a switch's case/default statements - try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] - # deindent closing brace(s) when after cursor - try %[ execute-keys -draft ^\h*[})] gh / [})] m 1 ] + try %{ + try %{ # line comment + execute-keys -draft k s ^\h*// + } catch %{ # block comment + 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 a switch's case/default statements + try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] + # deindent closing brace(s) when after cursor + try %[ execute-keys -draft ^\h*[})] gh / [})] m 1 ] + } = ~ diff --git a/test/indent/go/insert-comment/cmd b/test/indent/go/insert-comment/cmd new file mode 100644 index 00000000..e3036a40 --- /dev/null +++ b/test/indent/go/insert-comment/cmd @@ -0,0 +1 @@ +c diff --git a/test/indent/go/insert-comment/in b/test/indent/go/insert-comment/in new file mode 100644 index 00000000..fef0c47d --- /dev/null +++ b/test/indent/go/insert-comment/in @@ -0,0 +1,11 @@ +1 +// foo(bar,%( ) + +2 + // foo(bar,%( ) + +3 +// foo{%( ) + +4 + // foo{%( ) diff --git a/test/indent/go/insert-comment/out b/test/indent/go/insert-comment/out new file mode 100644 index 00000000..4d654000 --- /dev/null +++ b/test/indent/go/insert-comment/out @@ -0,0 +1,15 @@ +1 +// foo(bar, +// + +2 + // foo(bar, + // + +3 +// foo{ +// + +4 + // foo{ + // diff --git a/test/indent/go/insert-comment/rc b/test/indent/go/insert-comment/rc new file mode 100644 index 00000000..6e3ca7fd --- /dev/null +++ b/test/indent/go/insert-comment/rc @@ -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