diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index 3db474d7..cb97aaa7 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -11,14 +11,14 @@ hook global BufCreate .*[.](rust|rs) %{ # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -hook global WinSetOption filetype=rust %[ +hook global WinSetOption filetype=rust %< require-module rust hook window ModeChange pop:insert:.* -group rust-trim-indent rust-trim-indent hook window InsertChar \n -group rust-indent rust-indent-on-new-line hook window InsertChar \{ -group rust-indent rust-indent-on-opening-curly-brace - hook window InsertChar [)}] -group rust-indent rust-indent-on-closing + hook window InsertChar [)}\]] -group rust-indent rust-indent-on-closing hook -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-.+ } -] +> hook -group rust-highlight global WinSetOption filetype=rust %{ add-highlighter window/rust ref rust @@ -150,8 +150,8 @@ define-command -hidden rust-indent-on-new-line %~ try %+ execute-keys -draft k ^\h*where\b hh ^\h*\b(impl|fn|struct|enum|union)\b 1 + # preserve previous line indent try %{ execute-keys -draft K } - # 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 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 after non-empty lines not starting with operator and not ending with , or ; or { # XXX simplify this into a single without s try %< execute-keys -draft k s [^\h].+ \A[-+*/&|^})#] [,{](\h*/[/*].*|)$ j > @@ -181,11 +181,11 @@ define-command -hidden rust-indent-on-opening-curly-brace %[ _ ] -define-command -hidden rust-indent-on-closing %[ +define-command -hidden rust-indent-on-closing %~ evaluate-commands -draft -itersel %_ # align to opening curly brace or paren when alone on a line - try %< execute-keys -draft ^\h*[)}]$ h m 1 > + try %< execute-keys -draft ^\h*[)}\]]$ h m 1 > _ -] +~ § diff --git a/test/indent/rust/after-open-with-chars/in b/test/indent/rust/after-open-with-chars/in index 1f977479..3f3a93c8 100644 --- a/test/indent/rust/after-open-with-chars/in +++ b/test/indent/rust/after-open-with-chars/in @@ -1,3 +1,5 @@ Foo {bar,%( ) foo(bar,%( ) + + vec![bar,%( ) diff --git a/test/indent/rust/after-open-with-chars/out b/test/indent/rust/after-open-with-chars/out index e1475aab..3b4343b2 100644 --- a/test/indent/rust/after-open-with-chars/out +++ b/test/indent/rust/after-open-with-chars/out @@ -5,3 +5,7 @@ foo( bar, baz + + vec![ + bar, + baz diff --git a/test/indent/rust/after-open/in b/test/indent/rust/after-open/in index c403940b..b9d4e29b 100644 --- a/test/indent/rust/after-open/in +++ b/test/indent/rust/after-open/in @@ -1,3 +1,5 @@ Foo {%( ) foo(%( ) + + vec![%( ) diff --git a/test/indent/rust/after-open/out b/test/indent/rust/after-open/out index eaf2cdd4..6676dce3 100644 --- a/test/indent/rust/after-open/out +++ b/test/indent/rust/after-open/out @@ -3,3 +3,6 @@ foo( bar + + vec![ + bar diff --git a/test/indent/rust/align-closing-brack/cmd b/test/indent/rust/align-closing-brack/cmd new file mode 100644 index 00000000..5638d9f9 --- /dev/null +++ b/test/indent/rust/align-closing-brack/cmd @@ -0,0 +1 @@ +c] diff --git a/test/indent/rust/align-closing-brack/in b/test/indent/rust/align-closing-brack/in new file mode 100644 index 00000000..ff3e8631 --- /dev/null +++ b/test/indent/rust/align-closing-brack/in @@ -0,0 +1,3 @@ + vec![ + bar, + baz,%( ) diff --git a/test/indent/rust/align-closing-brack/out b/test/indent/rust/align-closing-brack/out new file mode 100644 index 00000000..00ec9c29 --- /dev/null +++ b/test/indent/rust/align-closing-brack/out @@ -0,0 +1,4 @@ + vec![ + bar, + baz, + ] diff --git a/test/indent/rust/align-closing-brack/rc b/test/indent/rust/align-closing-brack/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/align-closing-brack/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust