# http://fishshell.com # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](fish) %{ set buffer filetype fish } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter -group / 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 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 fish } hook global WinSetOption filetype=(?!fish).* %{ remove-hooks window fish-indent remove-hooks window fish-insert }