Merge remote-tracking branch 'pickfire/rust-indent' into master

This commit is contained in:
Maxime Coste 2020-10-01 19:07:05 +10:00
commit fcabffefe1
22 changed files with 176 additions and 14 deletions

View File

@ -146,18 +146,19 @@ define-command -hidden rust-indent-on-new-line %~
execute-keys K<a-x>1s^[^*]*(\*)<ret>& execute-keys K<a-x>1s^[^*]*(\*)<ret>&
] ]
} catch %` } 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 # preserve previous line indent
try %{ execute-keys -draft <semicolon> K <a-&> } 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 # 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-&> > 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 # indent after non-empty lines not starting with operator and not ending with , or ;
try %+ execute-keys -draft k <a-x> <a-k> ^\h*where\h*$ <ret> j <a-gt> + # XXX simplify this into a single <a-k> without s
# dedent after lines starting with . and ending with , or ; try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>](\h*/[/*].*|)$ <ret> j <a-gt> >
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\..*[,<semicolon>]\h*$ <ret> j <a-lt> _ # dedent after lines starting with . and ending with } or ) or , or ;
# deindent closing brace(s) when after cursor try %_ execute-keys -draft k <a-x> <a-k> ^\h*\..*[}),<semicolon>]\h*$ <ret> j <a-lt> _
try %= execute-keys -draft <a-x> <a-k> ^\h*[})] <ret> gh / [})] <ret> m <a-S> 1<a-&> = # 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 # todo dedent additional unmatched parenthesis
# try %& execute-keys -draft k <a-x> s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{ # try %& execute-keys -draft k <a-x> s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{
# count previous selections length # 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 # 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-&> ] 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 # 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> >
_ _
] ]

View File

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

View File

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

View File

@ -0,0 +1,9 @@
foo
.baz()
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

@ -1,5 +1,3 @@
impl X for T where%( )
impl X for T impl X for T
where%( ) where%( )

View File

@ -1,6 +1,3 @@
impl X for T where
bar
impl X for T impl X for T
where where
bar bar

View File

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

View File

@ -0,0 +1,2 @@
impl X for T%( )

View File

@ -0,0 +1,4 @@
impl X for T
where
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>bar<esc>

View File

@ -0,0 +1,2 @@
%( )

View File

@ -0,0 +1,3 @@
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,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

View File

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

View File

@ -0,0 +1,28 @@
.foo%( )
.foo()%( )
+ foo%( )
- foo%( )
* foo%( )
/ foo%( )
& foo%( )
| foo%( )
^ foo%( )
&& foo%( )
|| foo%( )
< foo%( )
> foo%( )
#[derive(Debug)]%( )

View 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

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

@ -33,3 +33,12 @@
union X<T> where T: Debug %( ) union X<T> where T: Debug %( )
if foo()
&& bar()
%( )
for x in group
.iter()
.sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
%( )

View File

@ -33,3 +33,12 @@
union X<T> where T: Debug { union X<T> where T: Debug {
if foo()
&& bar()
{
for x in group
.iter()
.sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
{