diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index a06ae7d1..f2fbfee1 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -148,16 +148,15 @@ define-command -hidden rust-indent-on-new-line %~ } catch %` # preserve previous line indent try %{ execute-keys -draft K } - # indent after lines ending with { or ( - try %[ execute-keys -draft k [{(]\h*$ j ] # indent after lines ending with [{(].+ and move first parameter to own line try %< execute-keys -draft [c[({],[)}] \A[({][^\n]+\n[^\n]*\n?\z L i > - # indent lines with a standalone where - try %+ execute-keys -draft k ^\h*where\h*$ j + - # dedent after lines starting with . and ending with , or ; - try %_ execute-keys -draft k ^\h*\..*[,]\h*$ j _ - # deindent closing brace(s) when after cursor - try %= execute-keys -draft ^\h*[})] gh / [})] m 1 = + # 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 s [^\h].+ \A[-+*/&|^})] [,](\h*/[/*].*|)$ j > + # dedent after lines starting with . and ending with } or ) or , or ; + try %_ execute-keys -draft k ^\h*\..*[}),]\h*$ j _ + # align to opening curly brace or paren when newline is inserted before a single closing + try %< execute-keys -draft ^\h*[)}] h m 1 > # todo dedent additional unmatched parenthesis # try %& execute-keys -draft k s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{ # count previous selections length 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.baz() 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/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 @@ +cbar 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..0b17056b --- /dev/null +++ b/test/indent/rust/line-start-with-operator/in @@ -0,0 +1,26 @@ + .foo%( ) + + .foo()%( ) + + + foo%( ) + + - foo%( ) + + * foo%( ) + + / foo%( ) + + & foo%( ) + + | foo%( ) + + ^ foo%( ) + + && foo%( ) + + || foo%( ) + + < foo%( ) + + > foo%( ) + 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..f81bfdec --- /dev/null +++ b/test/indent/rust/line-start-with-operator/out @@ -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 + 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