From 767b7e48dd9b79fb287f67d1577bb03911ed68d2 Mon Sep 17 00:00:00 2001 From: Justin Frank Date: Tue, 19 Mar 2019 09:51:42 -0700 Subject: [PATCH] Cleanup of fish.kak. Fixes #2775 --- rc/base/fish.kak | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/rc/base/fish.kak b/rc/base/fish.kak index 8e23ede4..24da9d20 100644 --- a/rc/base/fish.kak +++ b/rc/base/fish.kak @@ -31,39 +31,29 @@ add-highlighter shared/fish/code/ regex \b(and|begin|bg|bind|block|break|breakpo define-command -hidden fish-trim-indent %{ evaluate-commands -no-hooks -draft -itersel %{ # remove trailing white spaces - try %{ execute-keys -draft s\h+$d } + try %{ execute-keys -draft 1s^(\h+)$ d } } } define-command -hidden fish-indent-on-char %{ evaluate-commands -no-hooks -draft -itersel %{ # align middle and end structures to start and indent when necessary - try %{ execute-keys -draft ^\h*(else)$^\h*(if)s\A|\z) } - try %{ execute-keys -draft ^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|\z) } - try %{ execute-keys -draft ^\h*(case)$^\h*(switch)s\A|\z)) } + try %{ execute-keys -draft ^\h*(else)$^\h*(if)s\A|.\z1 } + try %{ execute-keys -draft ^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|.\z1 } + try %{ execute-keys -draft ^\h*(case)$^\h*(switch)s\A|.\z1 } } } define-command -hidden fish-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k s ^\h*#\h* y jgh P } # preserve previous line indent - try %{ execute-keys -draft K } - # filter previous line - try %{ execute-keys -draft k:fish-trim-indent } + try %{ execute-keys -draft \; K } + # cleanup trailing whitespaces from previous line + try %{ execute-keys -draft k s \h+$ d } # indent after start structure - try %{ execute-keys -draft k^\h*(begin|case|else|for|function|if|switch|while)\bj } - } -} - -define-command -hidden fish-insert-on-new-line %{ - evaluate-commands -no-hooks -draft -itersel %{ - # copy _#_ comment prefix and following white spaces - try %{ execute-keys -draft ks^\h*\K#\h*yjp } - # wisely add end structure - evaluate-commands -save-regs x %{ - try %{ execute-keys -draft ks^\h+"xy } catch %{ reg x '' } - try %{ execute-keys -draft k^x(begin|for|function|if|switch|while)jiXK^x(begin|for|function|if|switch|while).*\nxend$jxypjaend } - } + try %{ execute-keys -draft k^\h*(begin|case|else|for|function|if|while)\bj } } } @@ -77,7 +67,6 @@ hook -group fish-highlight global WinSetOption filetype=fish %{ hook global WinSetOption filetype=fish %{ hook window InsertChar .* -group fish-indent fish-indent-on-char - hook window InsertChar \n -group fish-insert fish-insert-on-new-line hook window InsertChar \n -group fish-indent fish-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ }