# http://fishshell.com # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](fish) %{ set-option buffer filetype fish } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/fish regions add-highlighter shared/fish/code default-region group add-highlighter shared/fish/double_string region '"' (?s\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)) } } } define-command -hidden fish-indent-on-new-line %{ evaluate-commands -no-hooks -draft -itersel %{ # preserve previous line indent try %{ execute-keys -draft K } # filter previous line try %{ execute-keys -draft k:fish-trim-indent } # 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 } } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group fish-highlight global WinSetOption filetype=fish %{ add-highlighter window/fish ref fish hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/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-.+ } }