diff options
| author | Maxime Coste <mawww@kakoune.org> | 2019-03-21 21:09:21 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2019-03-21 21:09:21 +1100 |
| commit | c3c3eb4acf3bf3620576fc9580fa3fdf02de1a69 (patch) | |
| tree | 14e7789fabd32096002d880f59cfb06ac4940ea7 | |
| parent | ef0c183ed70260cb7157db056bc162051541edaf (diff) | |
| parent | 767b7e48dd9b79fb287f67d1577bb03911ed68d2 (diff) | |
Merge remote-tracking branch 'laelath/fish-fixes'
| -rw-r--r-- | rc/base/fish.kak | 31 |
1 files 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 <a-x>s\h+$<ret>d } + try %{ execute-keys -draft <a-x> 1s^(\h+)$<ret> 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 <a-x><a-k>^\h*(else)$<ret><a-\;><a-?>^\h*(if)<ret>s\A|\z<ret>)<a-&> } - try %{ execute-keys -draft <a-x><a-k>^\h*(end)$<ret><a-\;><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|\z<ret>)<a-&> } - try %{ execute-keys -draft <a-x><a-k>^\h*(case)$<ret><a-\;><a-?>^\h*(switch)<ret>s\A|\z<ret>)<a-&>)<space><a-gt> } + try %{ execute-keys -draft <a-x><a-k>^\h*(else)$<ret><a-\;><a-?>^\h*(if)<ret>s\A|.\z<ret>1<a-&> } + try %{ execute-keys -draft <a-x><a-k>^\h*(end)$<ret><a-\;><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|.\z<ret>1<a-&> } + try %{ execute-keys -draft <a-x><a-k>^\h*(case)$<ret><a-\;><a-?>^\h*(switch)<ret>s\A|.\z<ret>1<a-&> } } } 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 <a-x> s ^\h*#\h* <ret> y jgh P } # preserve previous line indent - try %{ execute-keys -draft <space>K<a-&> } - # filter previous line - try %{ execute-keys -draft k:fish-trim-indent<ret> } + try %{ execute-keys -draft \; K <a-&> } + # cleanup trailing whitespaces from previous line + try %{ execute-keys -draft k <a-x> s \h+$ <ret> d } # indent after start structure - try %{ execute-keys -draft k<a-x><a-k>^\h*(begin|case|else|for|function|if|switch|while)\b<ret>j<a-gt> } - } -} - -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 k<a-x>s^\h*\K#\h*<ret>yjp } - # wisely add end structure - evaluate-commands -save-regs x %{ - try %{ execute-keys -draft k<a-x>s^\h+<ret>"xy } catch %{ reg x '' } - try %{ execute-keys -draft k<a-x><a-k>^<c-r>x(begin|for|function|if|switch|while)<ret>j<a-a>iX<a-\;>K<a-K>^<c-r>x(begin|for|function|if|switch|while).*\n<c-r>xend$<ret>jxypjaend<esc><a-lt> } - } + try %{ execute-keys -draft k<a-x><a-k>^\h*(begin|case|else|for|function|if|while)\b<ret>j<a-gt> } } } @@ -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-.+ } |
