Merge remote-tracking branch 'pickfire/rust-indent-bracket'

This commit is contained in:
Maxime Coste 2020-12-21 09:00:35 +11:00
commit 74b6c20a0d
25 changed files with 48 additions and 10 deletions

View File

@ -11,14 +11,14 @@ hook global BufCreate .*[.](rust|rs) %{
# Initialization # Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=rust %[ hook global WinSetOption filetype=rust %<
require-module rust require-module rust
hook window ModeChange pop:insert:.* -group rust-trim-indent rust-trim-indent 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 \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-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 -once -always window WinSetOption filetype=.* %{ remove-hooks window rust-.+ }
] >
hook -group rust-highlight global WinSetOption filetype=rust %{ hook -group rust-highlight global WinSetOption filetype=rust %{
add-highlighter window/rust ref rust add-highlighter window/rust ref rust
@ -150,15 +150,15 @@ define-command -hidden rust-indent-on-new-line %~
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-&> + 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 [{(].+ 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 after non-empty lines not starting with operator and not ending with , or ; or { # indent after non-empty lines not starting with operator and not ending with , or ; or {
# XXX simplify this into a single <a-k> without s # 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> > try %< execute-keys -draft k <a-x> s [^\h].+ <ret> <a-K> \A[-+*/&|^})<gt><lt>#] <ret> <a-K> [,<semicolon>{](\h*/[/*].*|)$ <ret> j <a-gt> >
# indent after lines ending with { # indent after lines ending with {
try %< execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> > try %< execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> >
# dedent after lines starting with . and ending with } or ) or , or ; # dedent after lines starting with . and ending with } or ) or , or ; or .await
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\..*[}),<semicolon>]\h*$ <ret> j <a-lt> _ try %_ execute-keys -draft k <a-x> <a-k> ^\h*\. <ret> <a-k>([}),<semicolon>]|\.await)\h*$ <ret> j <a-lt> _
# align to opening curly brace or paren when newline is inserted before a single closing # 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-&> > 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
@ -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 %_ evaluate-commands -draft -itersel %_
# align to opening curly brace or paren when alone on a line # align to opening curly brace or paren when alone on a line
try %< execute-keys -draft <a-h> <a-k> ^\h*[)}]$ <ret> h m <a-S> 1<a-&> > try %< execute-keys -draft <a-h> <a-k> ^\h*[)}\]]$ <ret> h m <a-S> 1<a-&> >
_ _
] ~
§ §

View File

@ -1,3 +1,5 @@
Foo {bar,%( ) Foo {bar,%( )
foo(bar,%( ) foo(bar,%( )
vec![bar,%( )

View File

@ -5,3 +5,7 @@
foo( foo(
bar, bar,
baz baz
vec![
bar,
baz

View File

@ -1,3 +1,5 @@
Foo {%( ) Foo {%( )
foo(%( ) foo(%( )
vec![%( )

View File

@ -3,3 +3,6 @@
foo( foo(
bar bar
vec![
bar

View File

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

View File

@ -0,0 +1,3 @@
vec![
bar,
baz,%( )

View File

@ -0,0 +1,4 @@
vec![
bar,
baz,
]

View File

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

View File

@ -0,0 +1,5 @@
foo()
.await%( )
foo().await%( )

View File

@ -0,0 +1,7 @@
foo()
.await
bar
foo().await
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,3 @@
source "%val{runtime}/colors/default.kak"
source "%val{runtime}/rc/filetype/rust.kak"
set buffer filetype rust