summaryrefslogtreecommitdiff
path: root/rc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2020-06-02 18:40:09 +1000
committerMaxime Coste <mawww@kakoune.org>2020-06-02 18:40:09 +1000
commitd43b6799cf807b4484e42fcdf3d9300a736fedd9 (patch)
treef5074fca3d802ea81065aa7338c98c3dab7b48d5 /rc
parent0fba373d1d1b852b00db54ad344c69629ef4e0da (diff)
parent12cafe3ed4dbc6d16fb7e54d07d6941985631942 (diff)
Merge remote-tracking branch 'pickfire/rust-dedent'
Diffstat (limited to 'rc')
-rw-r--r--rc/filetype/rust.kak17
1 files changed, 14 insertions, 3 deletions
diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak
index be440f75..14071511 100644
--- a/rc/filetype/rust.kak
+++ b/rc/filetype/rust.kak
@@ -75,15 +75,24 @@ define-command -hidden rust-indent-on-new-line %~
evaluate-commands -draft -itersel %<
# copy // comments prefix and following white spaces
try %{
- execute-keys -draft k <a-x> s ^\h*\K//[!/]?\h* <ret> y gh j P
- } catch %|
+ execute-keys -draft k <a-x> s ^\h*//[!/]{0,2}\h* <ret> y gh j P
+ } 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> _
+ # todo dedent additional unmatched parenthesis
+ # try %& execute-keys -draft k <a-x> s \((?:[^)(]+|\((?:[^)(]+|\([^)(]*\))*\))*\) l Gl s\) %sh{
+ # count previous selections length
+ # printf "j $(echo $kak_selections_length | wc -w) <a-lt>"
+ # } &
+ `
# filter previous line
try %{ execute-keys -draft k : rust-trim-indent <ret> }
>
@@ -93,6 +102,8 @@ define-command -hidden rust-indent-on-opening-curly-brace %[
evaluate-commands -draft -itersel %_
# 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 or fn 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> >
_
]