mirror of
https://github.com/mawww/kakoune.git
synced 2024-11-28 09:07:19 +03:00
Merge remote-tracking branch 'pickfire/rust-indent-bracket'
This commit is contained in:
commit
74b6c20a0d
@ -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,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-&> +
|
||||
# preserve previous line indent
|
||||
try %{ execute-keys -draft <semicolon> K <a-&> }
|
||||
# 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 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 after non-empty lines not starting with operator and not ending with , or ; or {
|
||||
# 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> >
|
||||
# indent after lines ending with {
|
||||
try %< execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> >
|
||||
# dedent after lines starting with . and ending with } or ) or , or ;
|
||||
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\..*[}),<semicolon>]\h*$ <ret> j <a-lt> _
|
||||
# dedent after lines starting with . and ending with } or ) or , or ; or .await
|
||||
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
|
||||
try %< execute-keys -draft <a-h> <a-k> ^\h*[)}] <ret> h m <a-S> 1<a-&> >
|
||||
# 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 %_
|
||||
# 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,%( )
|
||||
|
||||
vec![bar,%( )
|
||||
|
@ -5,3 +5,7 @@
|
||||
foo(
|
||||
bar,
|
||||
baz
|
||||
|
||||
vec![
|
||||
bar,
|
||||
baz
|
||||
|
@ -1,3 +1,5 @@
|
||||
Foo {%( )
|
||||
|
||||
foo(%( )
|
||||
|
||||
vec![%( )
|
||||
|
@ -3,3 +3,6 @@
|
||||
|
||||
foo(
|
||||
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,
|
||||
]
|
1
test/indent/rust/dedent-async/cmd
Normal file
1
test/indent/rust/dedent-async/cmd
Normal file
@ -0,0 +1 @@
|
||||
c<ret>bar<esc>
|
5
test/indent/rust/dedent-async/in
Normal file
5
test/indent/rust/dedent-async/in
Normal file
@ -0,0 +1,5 @@
|
||||
foo()
|
||||
.await%( )
|
||||
|
||||
foo().await%( )
|
||||
|
7
test/indent/rust/dedent-async/out
Normal file
7
test/indent/rust/dedent-async/out
Normal file
@ -0,0 +1,7 @@
|
||||
foo()
|
||||
.await
|
||||
bar
|
||||
|
||||
foo().await
|
||||
bar
|
||||
|
3
test/indent/rust/dedent-generic-closing-brace/rc
Normal file
3
test/indent/rust/dedent-generic-closing-brace/rc
Normal file
@ -0,0 +1,3 @@
|
||||
source "%val{runtime}/colors/default.kak"
|
||||
source "%val{runtime}/rc/filetype/rust.kak"
|
||||
set buffer filetype rust
|
3
test/indent/rust/dedent-if-closing-brace/rc
Normal file
3
test/indent/rust/dedent-if-closing-brace/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