diff options
| author | Maxime Coste <mawww@kakoune.org> | 2020-10-01 19:07:05 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2020-10-01 19:07:05 +1000 |
| commit | fcabffefe1e489805d680c20b1139be06d4020ca (patch) | |
| tree | b98c5d03e2cdc1b3135917b75aab9e56c291c7d2 | |
| parent | 88f6b65f35fdd62313acf80f2aa67d56c8a335c2 (diff) | |
| parent | bfca07da4d52b821c67a5b4e3eb056df9d98bd55 (diff) | |
Merge remote-tracking branch 'pickfire/rust-indent' into master
22 files changed, 176 insertions, 14 deletions
diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index d7ff4952..9117de8e 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -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> > _ ] diff --git a/test/indent/rust/after-variable/cmd b/test/indent/rust/after-variable/cmd new file mode 100644 index 00000000..932ef40d --- /dev/null +++ b/test/indent/rust/after-variable/cmd @@ -0,0 +1 @@ +c<ret>.baz()<esc> diff --git a/test/indent/rust/after-variable/in b/test/indent/rust/after-variable/in new file mode 100644 index 00000000..59951f6d --- /dev/null +++ b/test/indent/rust/after-variable/in @@ -0,0 +1,6 @@ + foo%( ) + + Foo(bar)%( ) + + Foo { bar }%( ) + diff --git a/test/indent/rust/after-variable/out b/test/indent/rust/after-variable/out new file mode 100644 index 00000000..4f5315a0 --- /dev/null +++ b/test/indent/rust/after-variable/out @@ -0,0 +1,9 @@ + foo + .baz() + + Foo(bar) + .baz() + + Foo { bar } + .baz() + diff --git a/test/indent/rust/after-variable/rc b/test/indent/rust/after-variable/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/after-variable/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust diff --git a/test/indent/rust/after-where/in b/test/indent/rust/after-where/in index 412f13d3..d935a00c 100644 --- a/test/indent/rust/after-where/in +++ b/test/indent/rust/after-where/in @@ -1,5 +1,3 @@ - impl X for T where%( ) - impl X for T where%( ) diff --git a/test/indent/rust/after-where/out b/test/indent/rust/after-where/out index 3cc8383e..caa373e4 100644 --- a/test/indent/rust/after-where/out +++ b/test/indent/rust/after-where/out @@ -1,6 +1,3 @@ - impl X for T where - bar - impl X for T where bar diff --git a/test/indent/rust/before-where/cmd b/test/indent/rust/before-where/cmd new file mode 100644 index 00000000..fe3daa48 --- /dev/null +++ b/test/indent/rust/before-where/cmd @@ -0,0 +1 @@ +c<ret>where<ret>bar<esc> diff --git a/test/indent/rust/before-where/in b/test/indent/rust/before-where/in new file mode 100644 index 00000000..0c1161c1 --- /dev/null +++ b/test/indent/rust/before-where/in @@ -0,0 +1,2 @@ + impl X for T%( ) + diff --git a/test/indent/rust/before-where/out b/test/indent/rust/before-where/out new file mode 100644 index 00000000..caa373e4 --- /dev/null +++ b/test/indent/rust/before-where/out @@ -0,0 +1,4 @@ + impl X for T + where + bar + diff --git a/test/indent/rust/before-where/rc b/test/indent/rust/before-where/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/before-where/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust diff --git a/test/indent/rust/empty-line/cmd b/test/indent/rust/empty-line/cmd new file mode 100644 index 00000000..8682d51e --- /dev/null +++ b/test/indent/rust/empty-line/cmd @@ -0,0 +1 @@ +c<ret>bar<esc> diff --git a/test/indent/rust/empty-line/in b/test/indent/rust/empty-line/in new file mode 100644 index 00000000..e4ed2188 --- /dev/null +++ b/test/indent/rust/empty-line/in @@ -0,0 +1,2 @@ + %( ) + diff --git a/test/indent/rust/empty-line/out b/test/indent/rust/empty-line/out new file mode 100644 index 00000000..4567eae7 --- /dev/null +++ b/test/indent/rust/empty-line/out @@ -0,0 +1,3 @@ + + bar + diff --git a/test/indent/rust/empty-line/rc b/test/indent/rust/empty-line/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/empty-line/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust diff --git a/test/indent/rust/line-start-with-operator/bar b/test/indent/rust/line-start-with-operator/bar new file mode 100644 index 00000000..3aa5220d --- /dev/null +++ b/test/indent/rust/line-start-with-operator/bar @@ -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 + diff --git a/test/indent/rust/line-start-with-operator/cmd b/test/indent/rust/line-start-with-operator/cmd new file mode 100644 index 00000000..8682d51e --- /dev/null +++ b/test/indent/rust/line-start-with-operator/cmd @@ -0,0 +1 @@ +c<ret>bar<esc> diff --git a/test/indent/rust/line-start-with-operator/in b/test/indent/rust/line-start-with-operator/in new file mode 100644 index 00000000..063f771e --- /dev/null +++ b/test/indent/rust/line-start-with-operator/in @@ -0,0 +1,28 @@ + .foo%( ) + + .foo()%( ) + + + foo%( ) + + - foo%( ) + + * foo%( ) + + / foo%( ) + + & foo%( ) + + | foo%( ) + + ^ foo%( ) + + && foo%( ) + + || foo%( ) + + < foo%( ) + + > foo%( ) + + #[derive(Debug)]%( ) + diff --git a/test/indent/rust/line-start-with-operator/out b/test/indent/rust/line-start-with-operator/out new file mode 100644 index 00000000..f270d0d9 --- /dev/null +++ b/test/indent/rust/line-start-with-operator/out @@ -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 + diff --git a/test/indent/rust/line-start-with-operator/rc b/test/indent/rust/line-start-with-operator/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/line-start-with-operator/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust diff --git a/test/indent/rust/on-open-paren/in b/test/indent/rust/on-open-paren/in index 1ca71d62..661f2331 100644 --- a/test/indent/rust/on-open-paren/in +++ b/test/indent/rust/on-open-paren/in @@ -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)) + %( ) + diff --git a/test/indent/rust/on-open-paren/out b/test/indent/rust/on-open-paren/out index de125ea7..60973f8a 100644 --- a/test/indent/rust/on-open-paren/out +++ b/test/indent/rust/on-open-paren/out @@ -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)) + { + |
