Rust improve align after partial statement
This commit is contained in:
parent
11d98a07dc
commit
5c8dfcdfa9
|
@ -148,16 +148,15 @@ define-command -hidden rust-indent-on-new-line %~
|
|||
} catch %`
|
||||
# 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> ]
|
||||
# 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 lines with a standalone where
|
||||
try %+ execute-keys -draft k <a-x> <a-k> ^\h*where\h*$ <ret> j <a-gt> +
|
||||
# dedent after lines starting with . and ending with , or ;
|
||||
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\..*[,<semicolon>]\h*$ <ret> j <a-lt> _
|
||||
# deindent closing brace(s) when after cursor
|
||||
try %= execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> =
|
||||
# indent after non-empty lines not starting with operator and not ending with , or ;
|
||||
# XXX s [^\h]* is workaround for broken negate match #3766, use this later
|
||||
try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>] <ret> <a-K> [,<semicolon>](\h*/[/*].*|)$ <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
|
||||
try %< execute-keys -draft <a-h> <a-k> ^\h*[)}] <ret> h m <a-S> 1<a-&> >
|
||||
# todo dedent additional unmatched parenthesis
|
||||
# try %& execute-keys -draft k <a-x> s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{
|
||||
# count previous selections length
|
||||
|
|
1
test/indent/rust/after-variable/cmd
Normal file
1
test/indent/rust/after-variable/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>.baz()<esc>
|
6
test/indent/rust/after-variable/in
Normal file
6
test/indent/rust/after-variable/in
Normal file
|
@ -0,0 +1,6 @@
|
|||
foo%( )
|
||||
|
||||
Foo(bar)%( )
|
||||
|
||||
Foo { bar }%( )
|
||||
|
9
test/indent/rust/after-variable/out
Normal file
9
test/indent/rust/after-variable/out
Normal file
|
@ -0,0 +1,9 @@
|
|||
foo
|
||||
.baz()
|
||||
|
||||
Foo(bar)
|
||||
.baz()
|
||||
|
||||
Foo { bar }
|
||||
.baz()
|
||||
|
3
test/indent/rust/after-variable/rc
Normal file
3
test/indent/rust/after-variable/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/rust.kak"
|
||||
set buffer filetype rust
|
|
@ -1,5 +1,3 @@
|
|||
impl X for T where%( )
|
||||
|
||||
impl X for T
|
||||
where%( )
|
||||
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
impl X for T where
|
||||
bar
|
||||
|
||||
impl X for T
|
||||
where
|
||||
bar
|
||||
|
|
36
test/indent/rust/line-start-with-operator/bar
Normal file
36
test/indent/rust/line-start-with-operator/bar
Normal file
|
@ -0,0 +1,36 @@
|
|||
.foo
|
||||
bar
|
||||
|
||||
+ foo
|
||||
bar
|
||||
|
||||
- foo
|
||||
bar
|
||||
|
||||
* foo
|
||||
bar
|
||||
|
||||
/ foo
|
||||
bar
|
||||
|
||||
& foo
|
||||
bar
|
||||
|
||||
| foo
|
||||
bar
|
||||
|
||||
^ foo
|
||||
bar
|
||||
|
||||
&& foo
|
||||
bar
|
||||
|
||||
|| foo
|
||||
bar
|
||||
|
||||
< foo
|
||||
bar
|
||||
|
||||
> foo
|
||||
bar
|
||||
|
1
test/indent/rust/line-start-with-operator/cmd
Normal file
1
test/indent/rust/line-start-with-operator/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>bar<esc>
|
26
test/indent/rust/line-start-with-operator/in
Normal file
26
test/indent/rust/line-start-with-operator/in
Normal file
|
@ -0,0 +1,26 @@
|
|||
.foo%( )
|
||||
|
||||
.foo()%( )
|
||||
|
||||
+ foo%( )
|
||||
|
||||
- foo%( )
|
||||
|
||||
* foo%( )
|
||||
|
||||
/ foo%( )
|
||||
|
||||
& foo%( )
|
||||
|
||||
| foo%( )
|
||||
|
||||
^ foo%( )
|
||||
|
||||
&& foo%( )
|
||||
|
||||
|| foo%( )
|
||||
|
||||
< foo%( )
|
||||
|
||||
> foo%( )
|
||||
|
39
test/indent/rust/line-start-with-operator/out
Normal file
39
test/indent/rust/line-start-with-operator/out
Normal file
|
@ -0,0 +1,39 @@
|
|||
.foo
|
||||
bar
|
||||
|
||||
.foo()
|
||||
bar
|
||||
|
||||
+ foo
|
||||
bar
|
||||
|
||||
- foo
|
||||
bar
|
||||
|
||||
* foo
|
||||
bar
|
||||
|
||||
/ foo
|
||||
bar
|
||||
|
||||
& foo
|
||||
bar
|
||||
|
||||
| foo
|
||||
bar
|
||||
|
||||
^ foo
|
||||
bar
|
||||
|
||||
&& foo
|
||||
bar
|
||||
|
||||
|| foo
|
||||
bar
|
||||
|
||||
< foo
|
||||
bar
|
||||
|
||||
> foo
|
||||
bar
|
||||
|
3
test/indent/rust/line-start-with-operator/rc
Normal file
3
test/indent/rust/line-start-with-operator/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/rust.kak"
|
||||
set buffer filetype rust
|
Loading…
Reference in New Issue
Block a user