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
This commit is contained in:
Grant Moyer 2019-03-27 13:52:20 -04:00
parent 4b98b89437
commit 71c5077bec
17 changed files with 54 additions and 6 deletions

View File

@ -52,8 +52,8 @@ define-command -hidden rust-indent-on-new-line %~
try %{ execute-keys -draft k : rust-trim-indent <ret> }
# 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> & }
# indent after lines ending with [{(].+ and move first parameter to own line
try %< execute-keys -draft [c[({],[)}] <ret> <a-k> \A[({][^\n]+\n[^\n]*\n?\z <ret> L i<ret><esc> <gt> <a-S> <a-&> >
>
~
@ -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 <a-h> <a-k> ^\h+\}$ <ret> h m s \A|.\z <ret> 1<a-&> ]
# align to opening curly brace or paren when alone on a line
try %< execute-keys -draft <a-h> <a-k> ^\h*[)}]$ <ret> h m <a-S> 1<a-&> >
_
]
@ -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-.+ }
]

View File

@ -0,0 +1 @@
c<ret>baz<esc>

View File

@ -0,0 +1,3 @@
Foo {bar,%( )
foo(bar,%( )

View File

@ -0,0 +1,7 @@
Foo {
bar,
baz
foo(
bar,
baz

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/rust.kak"
set buffer filetype rust

View File

@ -0,0 +1 @@
c<ret>bar<esc>

View File

@ -0,0 +1,3 @@
Foo {%( )
foo(%( )

View File

@ -0,0 +1,5 @@
Foo {
bar
foo(
bar

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/rust.kak"
set buffer filetype rust

View File

@ -0,0 +1 @@
c<ret>}<esc>

View File

@ -0,0 +1,3 @@
Foo {
bar,
baz,%( )

View File

@ -0,0 +1,4 @@
Foo {
bar,
baz,
}

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/rust.kak"
set buffer filetype rust

View File

@ -0,0 +1 @@
c<ret>)<esc>

View File

@ -0,0 +1,3 @@
foo(
bar,
baz,%( )

View File

@ -0,0 +1,4 @@
foo(
bar,
baz,
)

View File

@ -0,0 +1,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/rust.kak"
set buffer filetype rust