From ffbdcaa95cf429d55948730523563f5d83aa9978 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Thu, 17 Dec 2020 11:19:23 +0800 Subject: [PATCH 1/3] Rust handle [ indent like { and ( --- rc/filetype/rust.kak | 16 ++++++++-------- test/indent/rust/after-open-with-chars/in | 2 ++ test/indent/rust/after-open-with-chars/out | 4 ++++ test/indent/rust/after-open/in | 2 ++ test/indent/rust/after-open/out | 3 +++ test/indent/rust/align-closing-brack/cmd | 1 + test/indent/rust/align-closing-brack/in | 3 +++ test/indent/rust/align-closing-brack/out | 4 ++++ test/indent/rust/align-closing-brack/rc | 3 +++ 9 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 test/indent/rust/align-closing-brack/cmd create mode 100644 test/indent/rust/align-closing-brack/in create mode 100644 test/indent/rust/align-closing-brack/out create mode 100644 test/indent/rust/align-closing-brack/rc 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 From 1965b909e17aae498f27ab95a236c25e4dd61bc2 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Thu, 17 Dec 2020 20:07:44 +0800 Subject: [PATCH 2/3] Rust dedent after .await --- rc/filetype/rust.kak | 4 ++-- test/indent/rust/dedent-async/cmd | 1 + test/indent/rust/dedent-async/in | 5 +++++ test/indent/rust/dedent-async/out | 7 +++++++ test/indent/rust/dedent-async/rc | 3 +++ 5 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 test/indent/rust/dedent-async/cmd create mode 100644 test/indent/rust/dedent-async/in create mode 100644 test/indent/rust/dedent-async/out create mode 100644 test/indent/rust/dedent-async/rc diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index cb97aaa7..d4016fd4 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -157,8 +157,8 @@ define-command -hidden rust-indent-on-new-line %~ try %< execute-keys -draft k s [^\h].+ \A[-+*/&|^})#] [,{](\h*/[/*].*|)$ j > # indent after lines ending with { try %< execute-keys -draft k \{$ j > - # dedent after lines starting with . and ending with } or ) or , or ; - try %_ execute-keys -draft k ^\h*\..*[}),]\h*$ j _ + # dedent after lines starting with . and ending with } or ) or , or ; or .await + try %_ execute-keys -draft k ^\h*\. ([}),]|\.await)\h*$ j _ # align to opening curly brace or paren when newline is inserted before a single closing try %< execute-keys -draft ^\h*[)}] h m 1 > # todo dedent additional unmatched parenthesis diff --git a/test/indent/rust/dedent-async/cmd b/test/indent/rust/dedent-async/cmd new file mode 100644 index 00000000..8682d51e --- /dev/null +++ b/test/indent/rust/dedent-async/cmd @@ -0,0 +1 @@ +cbar diff --git a/test/indent/rust/dedent-async/in b/test/indent/rust/dedent-async/in new file mode 100644 index 00000000..19fba70f --- /dev/null +++ b/test/indent/rust/dedent-async/in @@ -0,0 +1,5 @@ + foo() + .await%( ) + + foo().await%( ) + diff --git a/test/indent/rust/dedent-async/out b/test/indent/rust/dedent-async/out new file mode 100644 index 00000000..3ed467d8 --- /dev/null +++ b/test/indent/rust/dedent-async/out @@ -0,0 +1,7 @@ + foo() + .await + bar + + foo().await + bar + diff --git a/test/indent/rust/dedent-async/rc b/test/indent/rust/dedent-async/rc new file mode 100644 index 00000000..64064c25 --- /dev/null +++ b/test/indent/rust/dedent-async/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/filetype/rust.kak" +set buffer filetype rust From a955d99fe3e16ce6f6ab7c0670951187adc43cb2 Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Thu, 17 Dec 2020 20:08:26 +0800 Subject: [PATCH 3/3] Rust test rename deindent to dedent --- .../cmd | 0 .../in | 0 .../out | 0 .../rc | 0 .../cmd | 0 .../in | 0 .../out | 0 .../rc | 0 .../{deindent-if-closing-brace => dedent-if-closing-brace}/cmd | 0 .../{deindent-if-closing-brace => dedent-if-closing-brace}/in | 0 .../{deindent-if-closing-brace => dedent-if-closing-brace}/out | 0 .../{deindent-if-closing-brace => dedent-if-closing-brace}/rc | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename test/indent/rust/{deindent-function-closing-brace => dedent-function-closing-brace}/cmd (100%) rename test/indent/rust/{deindent-function-closing-brace => dedent-function-closing-brace}/in (100%) rename test/indent/rust/{deindent-function-closing-brace => dedent-function-closing-brace}/out (100%) rename test/indent/rust/{deindent-function-closing-brace => dedent-function-closing-brace}/rc (100%) rename test/indent/rust/{deindent-generic-closing-brace => dedent-generic-closing-brace}/cmd (100%) rename test/indent/rust/{deindent-generic-closing-brace => dedent-generic-closing-brace}/in (100%) rename test/indent/rust/{deindent-generic-closing-brace => dedent-generic-closing-brace}/out (100%) rename test/indent/rust/{deindent-generic-closing-brace => dedent-generic-closing-brace}/rc (100%) rename test/indent/rust/{deindent-if-closing-brace => dedent-if-closing-brace}/cmd (100%) rename test/indent/rust/{deindent-if-closing-brace => dedent-if-closing-brace}/in (100%) rename test/indent/rust/{deindent-if-closing-brace => dedent-if-closing-brace}/out (100%) rename test/indent/rust/{deindent-if-closing-brace => dedent-if-closing-brace}/rc (100%) diff --git a/test/indent/rust/deindent-function-closing-brace/cmd b/test/indent/rust/dedent-function-closing-brace/cmd similarity index 100% rename from test/indent/rust/deindent-function-closing-brace/cmd rename to test/indent/rust/dedent-function-closing-brace/cmd diff --git a/test/indent/rust/deindent-function-closing-brace/in b/test/indent/rust/dedent-function-closing-brace/in similarity index 100% rename from test/indent/rust/deindent-function-closing-brace/in rename to test/indent/rust/dedent-function-closing-brace/in diff --git a/test/indent/rust/deindent-function-closing-brace/out b/test/indent/rust/dedent-function-closing-brace/out similarity index 100% rename from test/indent/rust/deindent-function-closing-brace/out rename to test/indent/rust/dedent-function-closing-brace/out diff --git a/test/indent/rust/deindent-function-closing-brace/rc b/test/indent/rust/dedent-function-closing-brace/rc similarity index 100% rename from test/indent/rust/deindent-function-closing-brace/rc rename to test/indent/rust/dedent-function-closing-brace/rc diff --git a/test/indent/rust/deindent-generic-closing-brace/cmd b/test/indent/rust/dedent-generic-closing-brace/cmd similarity index 100% rename from test/indent/rust/deindent-generic-closing-brace/cmd rename to test/indent/rust/dedent-generic-closing-brace/cmd diff --git a/test/indent/rust/deindent-generic-closing-brace/in b/test/indent/rust/dedent-generic-closing-brace/in similarity index 100% rename from test/indent/rust/deindent-generic-closing-brace/in rename to test/indent/rust/dedent-generic-closing-brace/in diff --git a/test/indent/rust/deindent-generic-closing-brace/out b/test/indent/rust/dedent-generic-closing-brace/out similarity index 100% rename from test/indent/rust/deindent-generic-closing-brace/out rename to test/indent/rust/dedent-generic-closing-brace/out diff --git a/test/indent/rust/deindent-generic-closing-brace/rc b/test/indent/rust/dedent-generic-closing-brace/rc similarity index 100% rename from test/indent/rust/deindent-generic-closing-brace/rc rename to test/indent/rust/dedent-generic-closing-brace/rc diff --git a/test/indent/rust/deindent-if-closing-brace/cmd b/test/indent/rust/dedent-if-closing-brace/cmd similarity index 100% rename from test/indent/rust/deindent-if-closing-brace/cmd rename to test/indent/rust/dedent-if-closing-brace/cmd diff --git a/test/indent/rust/deindent-if-closing-brace/in b/test/indent/rust/dedent-if-closing-brace/in similarity index 100% rename from test/indent/rust/deindent-if-closing-brace/in rename to test/indent/rust/dedent-if-closing-brace/in diff --git a/test/indent/rust/deindent-if-closing-brace/out b/test/indent/rust/dedent-if-closing-brace/out similarity index 100% rename from test/indent/rust/deindent-if-closing-brace/out rename to test/indent/rust/dedent-if-closing-brace/out diff --git a/test/indent/rust/deindent-if-closing-brace/rc b/test/indent/rust/dedent-if-closing-brace/rc similarity index 100% rename from test/indent/rust/deindent-if-closing-brace/rc rename to test/indent/rust/dedent-if-closing-brace/rc