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
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2014-07-14 22:42:19 +02:00
|
|
|
addhl -group / regions -default code fish \
|
|
|
|
double_string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
single_string "'" "'" '' \
|
|
|
|
comment '#' '$' ''
|
2014-07-02 23:13:01 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2014-07-05 00:49:51 +02:00
|
|
|
# Command names are collected using `builtin --names` and 'eval' from `functions --names`
|
2016-04-21 21:43:17 +02:00
|
|
|
addhl -group /fish/code regex \b(and|begin|bg|bind|block|break|breakpoint|builtin|case|cd|command|commandline|complete|contains|continue|count|echo|else|emit|end|eval|exec|exit|fg|for|function|functions|history|if|jobs|not|or|printf|pwd|random|read|return|set|set_color|source|status|switch|test|ulimit|while)\b 0:keyword
|
2014-07-02 23:13:01 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2014-07-03 01:33:06 +02:00
|
|
|
def -hidden _fish_filter_around_selections %{
|
2016-09-27 11:48:46 +02:00
|
|
|
eval -no-hooks -draft -itersel %{
|
2016-09-27 11:47:28 +02:00
|
|
|
# remove trailing white spaces
|
|
|
|
try %{ exec -draft <a-x>s\h+$<ret>d }
|
|
|
|
}
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
|
2014-07-03 17:50:48 +02:00
|
|
|
def -hidden _fish_indent_on_char %{
|
2016-09-27 11:48:46 +02:00
|
|
|
eval -no-hooks -draft -itersel %{
|
2016-09-27 12:08:42 +02:00
|
|
|
# align middle and end structures to start and indent when necessary
|
|
|
|
try %{ exec -draft <a-x><a-k>^\h*(else)$<ret><a-\;><a-?>^\h*(if)<ret>s\A|\Z<ret>'<a-&> }
|
|
|
|
try %{ exec -draft <a-x><a-k>^\h*(end)$<ret><a-\;><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|\Z<ret>'<a-&> }
|
|
|
|
try %{ exec -draft <a-x><a-k>^\h*(case)$<ret><a-\;><a-?>^\h*(switch)<ret>s\A|\Z<ret>'<a-&>'<space><a-gt> }
|
2014-07-03 17:50:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-02 23:13:01 +02:00
|
|
|
def -hidden _fish_indent_on_new_line %{
|
2016-09-27 11:48:46 +02:00
|
|
|
eval -no-hooks -draft -itersel %{
|
2014-07-02 23:13:01 +02:00
|
|
|
# preserve previous line indent
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft <space>K<a-&> }
|
2014-07-03 01:33:06 +02:00
|
|
|
# filter previous line
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft k:_fish_filter_around_selections<ret> }
|
2016-09-27 12:08:42 +02:00
|
|
|
# indent after start structure
|
|
|
|
try %{ exec -draft kx<a-k>^\h*(begin|case|else|for|function|if|switch|while)\b<ret>j<a-gt> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def -hidden _fish_insert_on_new_line %{
|
|
|
|
eval -no-hooks -draft -itersel %{
|
|
|
|
# copy _#_ comment prefix and following white spaces
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft kxs^\h*\K#\h*<ret>yjp }
|
2016-09-27 12:08:42 +02:00
|
|
|
# wisely add end structure
|
|
|
|
eval -save-regs x %{
|
|
|
|
try %{ exec -draft kxs^\h+<ret>"xy } catch %{ reg x '' }
|
|
|
|
try %{ exec -draft kx<a-k>^<c-r>x(begin|for|function|if|switch|while)<ret>j<a-a>iX<a-\;>K<a-K>^<c-r>x(begin|for|function|if|switch|while).*\n<c-r>xend$<ret>jxypjaend<esc><a-lt> }
|
|
|
|
}
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook -group fish-highlight global WinSetOption filetype=fish %{ addhl ref fish }
|
2014-07-02 23:13:01 +02:00
|
|
|
|
2016-09-25 15:15:07 +02:00
|
|
|
hook global WinSetOption filetype=fish %{
|
2014-07-03 17:50:48 +02:00
|
|
|
hook window InsertChar .* -group fish-indent _fish_indent_on_char
|
2014-07-02 23:13:01 +02:00
|
|
|
hook window InsertChar \n -group fish-indent _fish_indent_on_new_line
|
2016-09-27 12:08:42 +02:00
|
|
|
hook window InsertChar \n -group fish-insert _fish_insert_on_new_line
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-01 15:09:59 +02:00
|
|
|
hook -group fish-highlight global WinSetOption filetype=(?!fish).* %{ rmhl fish }
|
2016-09-28 08:45:01 +02:00
|
|
|
|
2014-07-02 23:13:01 +02:00
|
|
|
hook global WinSetOption filetype=(?!fish).* %{
|
|
|
|
rmhooks window fish-indent
|
2016-09-27 12:08:42 +02:00
|
|
|
rmhooks window fish-insert
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|