From 71c5077bec603044146db2e9e067de9b776e96ee Mon Sep 17 00:00:00 2001 From: Grant Moyer Date: Wed, 27 Mar 2019 13:52:20 -0400 Subject: [PATCH] Block indent on newline when previous line is '(stuff' and move 'stuff' to own line Also, align closing paren on own line with opening paren --- rc/filetype/rust.kak | 12 ++++++------ test/indent/rust/after-open-with-chars/cmd | 1 + test/indent/rust/after-open-with-chars/in | 3 +++ test/indent/rust/after-open-with-chars/out | 7 +++++++ test/indent/rust/after-open-with-chars/rc | 3 +++ test/indent/rust/after-open/cmd | 1 + test/indent/rust/after-open/in | 3 +++ test/indent/rust/after-open/out | 5 +++++ test/indent/rust/after-open/rc | 3 +++ test/indent/rust/align-closing-brace/cmd | 1 + test/indent/rust/align-closing-brace/in | 3 +++ test/indent/rust/align-closing-brace/out | 4 ++++ test/indent/rust/align-closing-brace/rc | 3 +++ test/indent/rust/align-closing-paren/cmd | 1 + test/indent/rust/align-closing-paren/in | 3 +++ test/indent/rust/align-closing-paren/out | 4 ++++ test/indent/rust/align-closing-paren/rc | 3 +++ 17 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 test/indent/rust/after-open-with-chars/cmd create mode 100644 test/indent/rust/after-open-with-chars/in create mode 100644 test/indent/rust/after-open-with-chars/out create mode 100644 test/indent/rust/after-open-with-chars/rc create mode 100644 test/indent/rust/after-open/cmd create mode 100644 test/indent/rust/after-open/in create mode 100644 test/indent/rust/after-open/out create mode 100644 test/indent/rust/after-open/rc create mode 100644 test/indent/rust/align-closing-brace/cmd create mode 100644 test/indent/rust/align-closing-brace/in create mode 100644 test/indent/rust/align-closing-brace/out create mode 100644 test/indent/rust/align-closing-brace/rc create mode 100644 test/indent/rust/align-closing-paren/cmd create mode 100644 test/indent/rust/align-closing-paren/in create mode 100644 test/indent/rust/align-closing-paren/out create mode 100644 test/indent/rust/align-closing-paren/rc diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index f32264ee..28cb98c3 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -52,8 +52,8 @@ define-command -hidden rust-indent-on-new-line %~ try %{ execute-keys -draft k : rust-trim-indent } # 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 ending with [{(].+ and move first parameter to own line + try %< execute-keys -draft [c[({],[)}] \A[({][^\n]+\n[^\n]*\n?\z L i > > ~ @@ -64,10 +64,10 @@ define-command -hidden rust-indent-on-opening-curly-brace %[ _ ] -define-command -hidden rust-indent-on-closing-curly-brace %[ +define-command -hidden rust-indent-on-closing %[ evaluate-commands -draft -itersel %_ - # align to opening curly brace when alone on a line - try %[ execute-keys -draft ^\h+\}$ h m s \A|.\z 1 ] + # align to opening curly brace or paren when alone on a line + try %< execute-keys -draft ^\h*[)}]$ h m 1 > _ ] @@ -83,7 +83,7 @@ hook global WinSetOption filetype=rust %[ hook window ModeChange insert:.* -group rust-trim-indent rust-trim-indent hook window InsertChar \n -group rust-indent rust-indent-on-new-line hook window InsertChar \{ -group rust-indent rust-indent-on-opening-curly-brace - hook window InsertChar \} -group rust-indent rust-indent-on-closing-curly-brace + hook window InsertChar [)}] -group rust-indent rust-indent-on-closing hook -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-.+ } ] diff --git a/test/indent/rust/after-open-with-chars/cmd b/test/indent/rust/after-open-with-chars/cmd new file mode 100644 index 00000000..b11ad994 --- /dev/null +++ b/test/indent/rust/after-open-with-chars/cmd @@ -0,0 +1 @@ +cbaz diff --git a/test/indent/rust/after-open-with-chars/in b/test/indent/rust/after-open-with-chars/in new file mode 100644 index 00000000..1f977479 --- /dev/null +++ b/test/indent/rust/after-open-with-chars/in @@ -0,0 +1,3 @@ + Foo {bar,%( ) + + foo(bar,%( ) diff --git a/test/indent/rust/after-open-with-chars/out b/test/indent/rust/after-open-with-chars/out new file mode 100644 index 00000000..e1475aab --- /dev/null +++ b/test/indent/rust/after-open-with-chars/out @@ -0,0 +1,7 @@ + Foo { + bar, + baz + + foo( + bar, + baz diff --git a/test/indent/rust/after-open-with-chars/rc b/test/indent/rust/after-open-with-chars/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/after-open-with-chars/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust diff --git a/test/indent/rust/after-open/cmd b/test/indent/rust/after-open/cmd new file mode 100644 index 00000000..8682d51e --- /dev/null +++ b/test/indent/rust/after-open/cmd @@ -0,0 +1 @@ +cbar diff --git a/test/indent/rust/after-open/in b/test/indent/rust/after-open/in new file mode 100644 index 00000000..c403940b --- /dev/null +++ b/test/indent/rust/after-open/in @@ -0,0 +1,3 @@ + Foo {%( ) + + foo(%( ) diff --git a/test/indent/rust/after-open/out b/test/indent/rust/after-open/out new file mode 100644 index 00000000..eaf2cdd4 --- /dev/null +++ b/test/indent/rust/after-open/out @@ -0,0 +1,5 @@ + Foo { + bar + + foo( + bar diff --git a/test/indent/rust/after-open/rc b/test/indent/rust/after-open/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/after-open/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust diff --git a/test/indent/rust/align-closing-brace/cmd b/test/indent/rust/align-closing-brace/cmd new file mode 100644 index 00000000..262bd1f0 --- /dev/null +++ b/test/indent/rust/align-closing-brace/cmd @@ -0,0 +1 @@ +c} diff --git a/test/indent/rust/align-closing-brace/in b/test/indent/rust/align-closing-brace/in new file mode 100644 index 00000000..323a91e3 --- /dev/null +++ b/test/indent/rust/align-closing-brace/in @@ -0,0 +1,3 @@ + Foo { + bar, + baz,%( ) diff --git a/test/indent/rust/align-closing-brace/out b/test/indent/rust/align-closing-brace/out new file mode 100644 index 00000000..22cfb580 --- /dev/null +++ b/test/indent/rust/align-closing-brace/out @@ -0,0 +1,4 @@ + Foo { + bar, + baz, + } diff --git a/test/indent/rust/align-closing-brace/rc b/test/indent/rust/align-closing-brace/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/align-closing-brace/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust diff --git a/test/indent/rust/align-closing-paren/cmd b/test/indent/rust/align-closing-paren/cmd new file mode 100644 index 00000000..0df56293 --- /dev/null +++ b/test/indent/rust/align-closing-paren/cmd @@ -0,0 +1 @@ +c) diff --git a/test/indent/rust/align-closing-paren/in b/test/indent/rust/align-closing-paren/in new file mode 100644 index 00000000..e356f41a --- /dev/null +++ b/test/indent/rust/align-closing-paren/in @@ -0,0 +1,3 @@ + foo( + bar, + baz,%( ) diff --git a/test/indent/rust/align-closing-paren/out b/test/indent/rust/align-closing-paren/out new file mode 100644 index 00000000..7650c5d4 --- /dev/null +++ b/test/indent/rust/align-closing-paren/out @@ -0,0 +1,4 @@ + foo( + bar, + baz, + ) diff --git a/test/indent/rust/align-closing-paren/rc b/test/indent/rust/align-closing-paren/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/align-closing-paren/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust