Rust always indent after {

This commit is contained in:
Ivan Tham 2020-10-04 23:40:47 +08:00
parent b0ae30a443
commit c148fdbe9a
3 changed files with 9 additions and 4 deletions

View File

@ -152,11 +152,11 @@ define-command -hidden rust-indent-on-new-line %~
try %{ execute-keys -draft <semicolon> K <a-&> }
# 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-&> >
# indent after non-empty lines not starting with operator and not ending with , or ;
# indent after non-empty lines not starting with operator and not ending with , or ; or {
# XXX simplify this into a single <a-k> without s
try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>](\h*/[/*].*|)$ <ret> j <a-gt> >
# addition to previous case where it starts with ) and ends with {
try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-k> \A\) <ret> <a-k> \{$ <ret> j <a-gt> >
try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>{](\h*/[/*].*|)$ <ret> j <a-gt> >
# indent after lines ending with {
try %< execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> >
# dedent after lines starting with . and ending with } or ) or , or ;
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\..*[}),<semicolon>]\h*$ <ret> j <a-lt> _
# align to opening curly brace or paren when newline is inserted before a single closing

View File

@ -29,3 +29,5 @@
fn foo(
) -> {%( )
} else {%( )

View File

@ -44,3 +44,6 @@
) -> {
bar
} else {
bar