Support dedent with rust fn qualifiers

This commit is contained in:
Ivan Tham 2021-03-07 14:12:01 +08:00
parent 4e594e034a
commit 8df5621334
3 changed files with 26 additions and 5 deletions

View File

@ -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 <a-x> <a-k> ^\h*where\b <ret> hh <a-?> ^\h*\b(impl|fn|struct|enum|union)\b <ret> <a-S> 1<a-&> +
# string literal parsing within extern does not handle escape
try %% execute-keys -draft k <a-x> <a-k> ^\h*where\b <ret> hh <a-?> ^\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 <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
@ -156,7 +157,7 @@ define-command -hidden rust-indent-on-new-line %~
# 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> >
try %+ execute-keys -draft k <a-x> <a-k> \{$ <ret> j <a-gt> +
# dedent after lines starting with . and ending with } or ) or , or ; or .await (} or ) or .await maybe with ?)
try %_ execute-keys -draft k <a-x> <a-k> ^\h*\. <ret> <a-k> ([,<semicolon>]|(([})]|\.await)\?*))\h*$ <ret> j <a-lt> _
# 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 <a-F> ) M <a-k> \A\(.*\)\h*\n\h*\{\z <ret> s \A|.\z <ret> 1<a-&> ]
# dedent standalone { after impl and related block without any { in between
try %< execute-keys -draft hh <a-?> ^\h*\b(impl|fn|struct|enum|union|if|for)\b <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> >
_
try %@ execute-keys -draft hh <a-?> ^\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 <ret> <a-K> \{ <ret> <a-semicolon> <semicolon> ll <a-x> <a-k> ^\h*\{$ <ret> <a-lt> @
~
]
define-command -hidden rust-indent-on-closing %~

View File

@ -3,6 +3,16 @@
T: Debug
%( )
pub async fn foo<T>(x: T)
where
T: Debug
%( )
pub(in std::fmt) const unsafe extern "C" fn foo<T>(x: T)
where
T: Debug
%( )
fn foo<T>(x: T) where T: Debug %( )
impl<T> X for T

View File

@ -3,6 +3,16 @@
T: Debug
{
pub async fn foo<T>(x: T)
where
T: Debug
{
pub(in std::fmt) const unsafe extern "C" fn foo<T>(x: T)
where
T: Debug
{
fn foo<T>(x: T) where T: Debug {
impl<T> X for T