2014-07-03 01:13:01 +04:00
|
|
|
# http://fishshell.com
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](fish) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype fish
|
2014-07-03 01:13:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-06-28 15:10:22 +03:00
|
|
|
add-highlighter shared/fish regions
|
|
|
|
add-highlighter shared/fish/code default-region group
|
2018-07-02 13:59:12 +03:00
|
|
|
add-highlighter shared/fish/double_string region '"' (?<!\\)(\\\\)*" group
|
|
|
|
add-highlighter shared/fish/single_string region "'" "'" fill string
|
|
|
|
add-highlighter shared/fish/comment region '#' '$' fill comment
|
2014-07-03 01:13:01 +04:00
|
|
|
|
2018-06-28 15:10:22 +03:00
|
|
|
add-highlighter shared/fish/double_string/ fill string
|
|
|
|
add-highlighter shared/fish/double_string/ regex (\$\w+)|(\{\$\w+\}) 0:variable
|
2014-07-03 01:13:01 +04:00
|
|
|
|
2018-06-28 15:10:22 +03:00
|
|
|
add-highlighter shared/fish/code/ regex (\$\w+)|(\{\$\w+\}) 0:variable
|
2014-07-03 01:13:01 +04:00
|
|
|
|
2014-07-05 02:49:51 +04:00
|
|
|
# Command names are collected using `builtin --names` and 'eval' from `functions --names`
|
2018-06-28 15:10:22 +03:00
|
|
|
add-highlighter shared/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-03 01:13:01 +04:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden fish-filter-around-selections %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2016-09-27 12:47:28 +03:00
|
|
|
# remove trailing white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft <a-x>s\h+$<ret>d }
|
2016-09-27 12:47:28 +03:00
|
|
|
}
|
2014-07-03 01:13:01 +04:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden fish-indent-on-char %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2016-09-27 13:08:42 +03:00
|
|
|
# align middle and end structures to start and indent when necessary
|
2018-03-25 03:45:27 +03:00
|
|
|
try %{ execute-keys -draft <a-x><a-k>^\h*(else)$<ret><a-\;><a-?>^\h*(if)<ret>s\A|\z<ret>)<a-&> }
|
|
|
|
try %{ execute-keys -draft <a-x><a-k>^\h*(end)$<ret><a-\;><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|\z<ret>)<a-&> }
|
|
|
|
try %{ execute-keys -draft <a-x><a-k>^\h*(case)$<ret><a-\;><a-?>^\h*(switch)<ret>s\A|\z<ret>)<a-&>)<space><a-gt> }
|
2014-07-03 19:50:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden fish-indent-on-new-line %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2014-07-03 01:13:01 +04:00
|
|
|
# preserve previous line indent
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft <space>K<a-&> }
|
2014-07-03 03:33:06 +04:00
|
|
|
# filter previous line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k:fish-filter-around-selections<ret> }
|
2016-09-27 13:08:42 +03:00
|
|
|
# indent after start structure
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k<a-x><a-k>^\h*(begin|case|else|for|function|if|switch|while)\b<ret>j<a-gt> }
|
2016-09-27 13:08:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden fish-insert-on-new-line %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2016-09-27 13:08:42 +03:00
|
|
|
# copy _#_ comment prefix and following white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k<a-x>s^\h*\K#\h*<ret>yjp }
|
2016-09-27 13:08:42 +03:00
|
|
|
# wisely add end structure
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -save-regs x %{
|
|
|
|
try %{ execute-keys -draft k<a-x>s^\h+<ret>"xy } catch %{ reg x '' }
|
|
|
|
try %{ execute-keys -draft k<a-x><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> }
|
2016-09-27 13:08:42 +03:00
|
|
|
}
|
2014-07-03 01:13:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-11-28 12:39:15 +03:00
|
|
|
hook -group fish-highlight global WinSetOption filetype=fish %{
|
|
|
|
add-highlighter window/fish ref fish
|
|
|
|
hook -once -always window WinSetOption filetype=(?!fish).* %{ remove-highlighter window/fish }
|
|
|
|
}
|
2014-07-03 01:13:01 +04:00
|
|
|
|
2016-09-25 16:15:07 +03:00
|
|
|
hook global WinSetOption filetype=fish %{
|
2017-01-13 03:56:30 +03:00
|
|
|
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
|
2016-09-28 09:45:01 +03:00
|
|
|
|
2018-11-28 12:39:15 +03:00
|
|
|
hook -once -always window WinSetOption filetype=(?!fish).* %{ remove-hooks window fish-.+ }
|
2014-07-03 01:13:01 +04:00
|
|
|
}
|