From 8df562133470d0f62c0c9c707ad0bba1e642d20c Mon Sep 17 00:00:00 2001 From: Ivan Tham Date: Sun, 7 Mar 2021 14:12:01 +0800 Subject: [PATCH] Support dedent with rust fn qualifiers --- rc/filetype/rust.kak | 11 ++++++----- test/indent/rust/on-open-paren/in | 10 ++++++++++ test/indent/rust/on-open-paren/out | 10 ++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/rc/filetype/rust.kak b/rc/filetype/rust.kak index 473a2e89..8764489c 100644 --- a/rc/filetype/rust.kak +++ b/rc/filetype/rust.kak @@ -147,7 +147,8 @@ define-command -hidden rust-indent-on-new-line %~ ] } catch %` # re-indent previous line if it starts with where to match previous block - try %+ execute-keys -draft k ^\h*where\b hh ^\h*\b(impl|fn|struct|enum|union)\b 1 + + # string literal parsing within extern does not handle escape + try %% execute-keys -draft k ^\h*where\b hh ^\h*\b(impl|(|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )(async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?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 @@ -156,7 +157,7 @@ define-command -hidden rust-indent-on-new-line %~ # XXX simplify this into a single without s try %< execute-keys -draft k s [^\h].+ \A[-+*/&|^})#] [,{](\h*/[/*].*|)$ j > # indent after lines ending with { - try %< execute-keys -draft k \{$ j > + try %+ execute-keys -draft k \{$ j + # dedent after lines starting with . and ending with } or ) or , or ; or .await (} or ) or .await maybe with ?) try %_ execute-keys -draft k ^\h*\. ([,]|(([})]|\.await)\?*))\h*$ j _ # dedent after lines ending with " => {}" - part of empty match @@ -175,12 +176,12 @@ define-command -hidden rust-indent-on-new-line %~ ~ define-command -hidden rust-indent-on-opening-curly-brace %[ - evaluate-commands -draft -itersel %_ + evaluate-commands -draft -itersel %~ # align indent with opening paren when { is entered on a new line after the closing paren try %[ execute-keys -draft h ) M \A\(.*\)\h*\n\h*\{\z s \A|.\z 1 ] # dedent standalone { after impl and related block without any { in between - try %< execute-keys -draft hh ^\h*\b(impl|fn|struct|enum|union|if|for)\b \{ ll ^\h*\{$ > - _ + try %@ execute-keys -draft hh ^\h*\b(impl|(|pub\ |pub\((crate|self|super|in\ (::)?([a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)(::[a-zA-Z][a-zA-Z0-9_]*|_[a-zA-Z0-9_]+)*)\)\ )(async\ |const\ )?(unsafe\ )?(extern\ ("[^"]*"\ )?)?fn|struct|enum|union|if|for)\b \{ ll ^\h*\{$ @ + ~ ] define-command -hidden rust-indent-on-closing %~ diff --git a/test/indent/rust/on-open-paren/in b/test/indent/rust/on-open-paren/in index 661f2331..cc452565 100644 --- a/test/indent/rust/on-open-paren/in +++ b/test/indent/rust/on-open-paren/in @@ -3,6 +3,16 @@ T: Debug %( ) + pub async fn foo(x: T) + where + T: Debug + %( ) + + pub(in std::fmt) const unsafe extern "C" fn foo(x: T) + where + T: Debug + %( ) + fn foo(x: T) where T: Debug %( ) impl X for T diff --git a/test/indent/rust/on-open-paren/out b/test/indent/rust/on-open-paren/out index 60973f8a..d7e4aad3 100644 --- a/test/indent/rust/on-open-paren/out +++ b/test/indent/rust/on-open-paren/out @@ -3,6 +3,16 @@ T: Debug { + pub async fn foo(x: T) + where + T: Debug + { + + pub(in std::fmt) const unsafe extern "C" fn foo(x: T) + where + T: Debug + { + fn foo(x: T) where T: Debug { impl X for T