Rust handle [ indent like { and (
This commit is contained in:
parent
ce96c3f262
commit
ffbdcaa95c
|
@ -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,8 +150,8 @@ 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> >
|
||||||
|
@ -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-&> >
|
||||||
_
|
_
|
||||||
]
|
~
|
||||||
|
|
||||||
§
|
§
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
Foo {bar,%( )
|
Foo {bar,%( )
|
||||||
|
|
||||||
foo(bar,%( )
|
foo(bar,%( )
|
||||||
|
|
||||||
|
vec![bar,%( )
|
||||||
|
|
|
@ -5,3 +5,7 @@
|
||||||
foo(
|
foo(
|
||||||
bar,
|
bar,
|
||||||
baz
|
baz
|
||||||
|
|
||||||
|
vec![
|
||||||
|
bar,
|
||||||
|
baz
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
Foo {%( )
|
Foo {%( )
|
||||||
|
|
||||||
foo(%( )
|
foo(%( )
|
||||||
|
|
||||||
|
vec![%( )
|
||||||
|
|
|
@ -3,3 +3,6 @@
|
||||||
|
|
||||||
foo(
|
foo(
|
||||||
bar
|
bar
|
||||||
|
|
||||||
|
vec![
|
||||||
|
bar
|
||||||
|
|
1
test/indent/rust/align-closing-brack/cmd
Normal file
1
test/indent/rust/align-closing-brack/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
c<ret>]<esc>
|
3
test/indent/rust/align-closing-brack/in
Normal file
3
test/indent/rust/align-closing-brack/in
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
vec![
|
||||||
|
bar,
|
||||||
|
baz,%( )
|
4
test/indent/rust/align-closing-brack/out
Normal file
4
test/indent/rust/align-closing-brack/out
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
vec![
|
||||||
|
bar,
|
||||||
|
baz,
|
||||||
|
]
|
3
test/indent/rust/align-closing-brack/rc
Normal file
3
test/indent/rust/align-closing-brack/rc
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
source "%val{runtime}/colors/default.kak"
|
||||||
|
source "%val{runtime}/rc/filetype/rust.kak"
|
||||||
|
set buffer filetype rust
|
Loading…
Reference in New Issue
Block a user