# http://fishshell.com # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufSetOption mimetype=text/x-fish %{ set buffer filetype fish } hook global BufCreate .*[.](fish) %{ set buffer filetype fish } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ addhl -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 kx^\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 kxs^\h*\K#\h*yjp } # wisely add end structure eval -save-regs x %{ try %{ exec -draft kxs^\h+"xy } catch %{ reg x '' } try %{ exec -draft kx^x(begin|for|function|if|switch|while)jiXK^x(begin|for|function|if|switch|while).*\nxend$jxypjaend } } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=fish %{ addhl ref fish hook window InsertChar .* -group fish-indent _fish_indent_on_char hook window InsertChar \n -group fish-indent _fish_indent_on_new_line hook window InsertChar \n -group fish-insert _fish_insert_on_new_line } hook global WinSetOption filetype=(?!fish).* %{ rmhl fish rmhooks window fish-indent rmhooks window fish-insert }