2014-07-02 23:13:01 +02:00
|
|
|
# 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 / multi_region -default code fish \
|
|
|
|
double_string (^|\h)" (?<!\\)(\\\\)*" '' \
|
|
|
|
single_string (^|\h)' (?<!\\)(\\\\)*' '' \
|
|
|
|
comment (^|\h)# $ ''
|
|
|
|
|
|
|
|
addhl -group /fish/double_string fill string
|
|
|
|
addhl -group /fish/double_string regex (\$\w+)|(\{\$\w+\}) 0:identifier
|
|
|
|
addhl -group /fish/single_string fill string
|
|
|
|
addhl -group /fish/comment fill comment
|
|
|
|
|
|
|
|
addhl -group /fish/code regex (\$\w+)|(\{\$\w+\}) 0:identifier
|
|
|
|
|
|
|
|
# Command names generated by fish
|
|
|
|
addhl -group /fish/code regex %sh{ printf '\<(%s)\>' $(printf '\Q%s\\E|' $(fish --command 'builtin --names' --command 'functions --names' | tr --delete ,)) } 0:keyword
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2014-07-03 01:33:06 +02:00
|
|
|
def -hidden _fish_filter_around_selections %{
|
2014-07-02 23:13:01 +02:00
|
|
|
eval -draft -itersel %{
|
2014-07-03 01:08:45 +02:00
|
|
|
exec <a-x>
|
2014-07-03 01:33:06 +02:00
|
|
|
# remove trailing white spaces
|
2014-07-03 01:08:45 +02:00
|
|
|
try %{ exec -draft s \h+$ <ret> d }
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def -hidden _fish_indent_on_new_line %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
# preserve previous line indent
|
|
|
|
try %{ exec -draft <space> K <a-&> }
|
2014-07-03 01:33:06 +02:00
|
|
|
# filter previous line
|
|
|
|
try %{ exec -draft k : _fish_filter_around_selections <ret> }
|
2014-07-02 23:13:01 +02:00
|
|
|
# copy '#' comment prefix and following white spaces
|
|
|
|
try %{ exec -draft k x s ^\h*\K#\h* <ret> y j p }
|
|
|
|
# indent after (begin|for|function|if|switch|while) commands and add 'end' command
|
2014-07-03 17:19:58 +02:00
|
|
|
try %{ exec -draft <space> k x <a-k> (begin|for|function|(?<!(else)\h+)if|switch|while) <ret> x y p j a end <esc> k <a-gt> }
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=fish %{
|
|
|
|
addhl ref fish
|
|
|
|
|
2014-07-03 01:33:06 +02:00
|
|
|
hook window InsertEnd .* -group fish-hooks _fish_filter_around_selections
|
2014-07-02 23:13:01 +02:00
|
|
|
hook window InsertChar \n -group fish-indent _fish_indent_on_new_line
|
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!fish).* %{
|
|
|
|
rmhl fish
|
|
|
|
rmhooks window fish-indent
|
|
|
|
rmhooks window fish-hooks
|
|
|
|
}
|