summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Tham <pickfire@riseup.net>2020-12-17 11:19:23 +0800
committerIvan Tham <pickfire@riseup.net>2020-12-17 11:19:23 +0800
commitffbdcaa95cf429d55948730523563f5d83aa9978 (patch)
tree03d1e09ef5dc1c472da834f7b7310dc271463580
parentce96c3f26246ca1d1ae380e5a14e2880256ded25 (diff)
Rust handle [ indent like { and (
-rw-r--r--rc/filetype/rust.kak16
-rw-r--r--test/indent/rust/after-open-with-chars/in2
-rw-r--r--test/indent/rust/after-open-with-chars/out4
-rw-r--r--test/indent/rust/after-open/in2
-rw-r--r--test/indent/rust/after-open/out3
-rw-r--r--test/indent/rust/align-closing-brack/cmd1
-rw-r--r--test/indent/rust/align-closing-brack/in3
-rw-r--r--test/indent/rust/align-closing-brack/out4
-rw-r--r--test/indent/rust/align-closing-brack/rc3
9 files changed, 30 insertions, 8 deletions
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 <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> >
@@ -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-&> >
_
-]
+~
§
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<ret>]<esc>
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