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 %{
|
2015-11-04 10:48:47 +01:00
|
|
|
# remove trailing white spaces
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft -itersel <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 %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
# deindent on (else|end) command insertion
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft <space><a-i>w<a-k>(else|end)<ret><a-lt> }
|
2014-07-03 17:50:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-02 23:13:01 +02:00
|
|
|
def -hidden _fish_indent_on_new_line %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
# 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> }
|
2014-07-02 23:13:01 +02:00
|
|
|
# copy '#' comment prefix and following white spaces
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft kxs^\h*\K#\h*<ret>yjp }
|
2014-07-03 17:47:11 +02:00
|
|
|
# indent after (case|else) commands
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft <space>kx<a-k>(case|else)<ret>j<a-gt> }
|
2014-07-02 23:13:01 +02:00
|
|
|
# indent after (begin|for|function|if|switch|while) commands and add 'end' command
|
2016-09-27 11:36:43 +02:00
|
|
|
try %{ exec -draft <space>kx<a-k>(begin|for|function|(?<!(else)\h+)if|switch|while)<ret>xypjaend<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-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
|
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!fish).* %{
|
|
|
|
rmhl fish
|
|
|
|
rmhooks window fish-indent
|
|
|
|
rmhooks window fish-hooks
|
|
|
|
}
|