Merge remote-tracking branch 'pickfire/rust-indent' into master
This commit is contained in:
commit
fcabffefe1
|
@ -146,18 +146,19 @@ define-command -hidden rust-indent-on-new-line %~
|
|||
execute-keys K<a-x>1s^[^*]*(\*)<ret>&
|
||||
]
|
||||
} catch %`
|
||||
# re-indent previous line if it starts with where to match previous block
|
||||
try %+ execute-keys -draft k <a-x> <a-k> ^\h*where\b <ret> hh <a-?> ^\h*\b(impl|fn|struct|enum|union)\b <ret> <a-S> 1<a-&> +
|
||||
# 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 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> >
|
||||
# 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
|
||||
|
@ -174,7 +175,7 @@ define-command -hidden rust-indent-on-opening-curly-brace %[
|
|||
# align indent with opening paren when { is entered on a new line after the closing paren
|
||||
try %[ execute-keys -draft h <a-F> ) M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ]
|
||||
# dedent standalone { after impl and related block without any { in between
|
||||
try %< execute-keys -draft hh <a-?> impl|fn|struct|enum|union <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> >
|
||||
try %< execute-keys -draft hh <a-?> ^\h*\b(impl|fn|struct|enum|union|if|for)\b <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> >
|
||||
_
|
||||
]
|
||||
|
||||
|
|
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
|
||||
|
|
1
test/indent/rust/before-where/cmd
Normal file
1
test/indent/rust/before-where/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>where<ret>bar<esc>
|
2
test/indent/rust/before-where/in
Normal file
2
test/indent/rust/before-where/in
Normal file
|
@ -0,0 +1,2 @@
|
|||
impl X for T%( )
|
||||
|
4
test/indent/rust/before-where/out
Normal file
4
test/indent/rust/before-where/out
Normal file
|
@ -0,0 +1,4 @@
|
|||
impl X for T
|
||||
where
|
||||
bar
|
||||
|
3
test/indent/rust/before-where/rc
Normal file
3
test/indent/rust/before-where/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
test/indent/rust/empty-line/cmd
Normal file
1
test/indent/rust/empty-line/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
c<ret>bar<esc>
|
2
test/indent/rust/empty-line/in
Normal file
2
test/indent/rust/empty-line/in
Normal file
|
@ -0,0 +1,2 @@
|
|||
%( )
|
||||
|
3
test/indent/rust/empty-line/out
Normal file
3
test/indent/rust/empty-line/out
Normal file
|
@ -0,0 +1,3 @@
|
|||
|
||||
bar
|
||||
|
3
test/indent/rust/empty-line/rc
Normal file
3
test/indent/rust/empty-line/rc
Normal file
|
@ -0,0 +1,3 @@
|
|||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/rust.kak"
|
||||
set buffer filetype rust
|
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>
|
28
test/indent/rust/line-start-with-operator/in
Normal file
28
test/indent/rust/line-start-with-operator/in
Normal file
|
@ -0,0 +1,28 @@
|
|||
.foo%( )
|
||||
|
||||
.foo()%( )
|
||||
|
||||
+ foo%( )
|
||||
|
||||
- foo%( )
|
||||
|
||||
* foo%( )
|
||||
|
||||
/ foo%( )
|
||||
|
||||
& foo%( )
|
||||
|
||||
| foo%( )
|
||||
|
||||
^ foo%( )
|
||||
|
||||
&& foo%( )
|
||||
|
||||
|| foo%( )
|
||||
|
||||
< foo%( )
|
||||
|
||||
> foo%( )
|
||||
|
||||
#[derive(Debug)]%( )
|
||||
|
42
test/indent/rust/line-start-with-operator/out
Normal file
42
test/indent/rust/line-start-with-operator/out
Normal file
|
@ -0,0 +1,42 @@
|
|||
.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
|
||||
|
||||
#[derive(Debug)]
|
||||
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
|
|
@ -33,3 +33,12 @@
|
|||
|
||||
union X<T> where T: Debug %( )
|
||||
|
||||
if foo()
|
||||
&& bar()
|
||||
%( )
|
||||
|
||||
for x in group
|
||||
.iter()
|
||||
.sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
|
||||
%( )
|
||||
|
||||
|
|
|
@ -33,3 +33,12 @@
|
|||
|
||||
union X<T> where T: Debug {
|
||||
|
||||
if foo()
|
||||
&& bar()
|
||||
{
|
||||
|
||||
for x in group
|
||||
.iter()
|
||||
.sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user