diff --git a/rc/fish.kak b/rc/fish.kak index 9f46516e..f0e2fd8e 100644 --- a/rc/fish.kak +++ b/rc/fish.kak @@ -33,10 +33,18 @@ addhl -group /fish/code regex %sh{ printf '\<(%s)\>' $(printf '\Q%s\\E|' $(fish # Commands # ‾‾‾‾‾‾‾‾ -def -hidden _fish_clean_around_selections %{ +def -hidden _fish_filter_around_selections %{ eval -draft -itersel %{ - # trailing white spaces - try %{ exec -draft s \h+$ d } + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _fish_indent_on_char %{ + eval -draft -itersel %{ + # deindent on (else|end) command insertion + try %{ exec -draft w (else|end) } } } @@ -44,12 +52,14 @@ def -hidden _fish_indent_on_new_line %{ eval -draft -itersel %{ # preserve previous line indent try %{ exec -draft K } - # cleanup previous line - try %{ exec -draft k : _fish_clean_around_selections } + # filter previous line + try %{ exec -draft k : _fish_filter_around_selections } # copy '#' comment prefix and following white spaces try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after (case|else) commands + try %{ exec -draft k x (case|else) j } # indent after (begin|for|function|if|switch|while) commands and add 'end' command - try %{ exec -draft k x (begin|for|function|if|switch|while) x y p j a end k } + try %{ exec -draft k x (begin|for|function|(? x y p j a end k } } } @@ -59,7 +69,8 @@ def -hidden _fish_indent_on_new_line %{ hook global WinSetOption filetype=fish %{ addhl ref fish - hook window InsertEnd .* -group fish-hooks _fish_clean_around_selections + hook window InsertEnd .* -group fish-hooks _fish_filter_around_selections + hook window InsertChar .* -group fish-indent _fish_indent_on_char hook window InsertChar \n -group fish-indent _fish_indent_on_new_line }