# http://fishshell.com # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](fish) %{ set buffer filetype fish } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/ regions -default code fish \ double_string '"' (?s\h+$d } } } def -hidden fish-indent-on-char %{ eval -no-hooks -draft -itersel %{ # align middle and end structures to start and indent when necessary try %{ exec -draft ^\h*(else)$^\h*(if)s\A|\z' } try %{ exec -draft ^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|\z' } try %{ exec -draft ^\h*(case)$^\h*(switch)s\A|\z'' } } } def -hidden fish-indent-on-new-line %{ eval -no-hooks -draft -itersel %{ # preserve previous line indent try %{ exec -draft K } # filter previous line try %{ exec -draft k:fish-filter-around-selections } # indent after start structure try %{ exec -draft k^\h*(begin|case|else|for|function|if|switch|while)\bj } } } def -hidden fish-insert-on-new-line %{ eval -no-hooks -draft -itersel %{ # copy _#_ comment prefix and following white spaces try %{ exec -draft ks^\h*\K#\h*yjp } # wisely add end structure eval -save-regs x %{ try %{ exec -draft ks^\h+"xy } catch %{ reg x '' } try %{ exec -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 ref 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 -group fish-highlight global WinSetOption filetype=(?!fish).* %{ remove-highlighter window/fish } hook global WinSetOption filetype=(?!fish).* %{ remove-hooks window fish-indent remove-hooks window fish-insert }