2014-07-02 23:13:01 +02:00
|
|
|
# http://fishshell.com
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](fish) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype fish
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
|
2019-04-11 01:48:46 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=fish %{
|
2019-03-13 19:15:59 +01:00
|
|
|
require-module fish
|
2019-04-11 01:48:46 +02:00
|
|
|
|
2022-04-30 11:27:12 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group fish-trim-indent fish-trim-indent
|
2019-04-11 01:48:46 +02:00
|
|
|
hook window InsertChar .* -group fish-indent fish-indent-on-char
|
2020-10-10 12:15:57 +02:00
|
|
|
hook window InsertChar \n -group fish-insert fish-insert-on-new-line
|
2019-04-11 01:48:46 +02:00
|
|
|
hook window InsertChar \n -group fish-indent fish-indent-on-new-line
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ }
|
2019-03-13 19:15:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-11 01:48:46 +02:00
|
|
|
hook -group fish-highlight global WinSetOption filetype=fish %{
|
|
|
|
add-highlighter window/fish ref fish
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fish }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-13 19:15:59 +01:00
|
|
|
provide-module fish %{
|
|
|
|
|
2014-07-02 23:13:01 +02:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-06-28 14:10:22 +02:00
|
|
|
add-highlighter shared/fish regions
|
|
|
|
add-highlighter shared/fish/code default-region group
|
2020-06-11 20:02:52 +02:00
|
|
|
add-highlighter shared/fish/double_string region (?<!\\)(?:\\\\)*\K" (?<!\\)(\\\\)*" group
|
|
|
|
add-highlighter shared/fish/single_string region (?<!\\)(?:\\\\)*\K' (?<!\\)(\\\\)*' fill string
|
2020-07-18 23:18:07 +02:00
|
|
|
add-highlighter shared/fish/comment region (?<!\\)(?:\\\\)*(?:^|\h)\K# '$' fill comment
|
2014-07-02 23:13:01 +02:00
|
|
|
|
2018-06-28 14:10:22 +02:00
|
|
|
add-highlighter shared/fish/double_string/ fill string
|
2020-09-05 07:36:31 +02:00
|
|
|
add-highlighter shared/fish/double_string/ regex ((?<!\\)(?:\\\\)*\K\$\w+)|(\{\$\w+\}) 0:variable
|
2014-07-02 23:13:01 +02:00
|
|
|
|
2020-09-05 07:36:31 +02:00
|
|
|
add-highlighter shared/fish/code/ regex (?<!\\)(?:\\\\)*\K(\$\w+)|(\{\$\w+\}) 0:variable
|
2014-07-02 23:13:01 +02:00
|
|
|
|
2020-05-16 22:10:19 +02:00
|
|
|
# Command names are collected using `builtin --names`.
|
2021-03-20 21:03:29 +01:00
|
|
|
add-highlighter shared/fish/code/ regex \b(?<![$-])(and|argparse|begin|bg|bind|block|break|breakpoint|builtin|case|cd|command|commandline|complete|contains|continue|count|disown|echo|else|emit|end|eval|exec|exit|false|fg|for|function|functions|history|if|jobs|math|not|or|printf|pwd|random|read|realpath|return|set|set_color|source|status|string|switch|test|time|true|ulimit|wait|while)\b(?!-) 0:keyword
|
2014-07-02 23:13:01 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden fish-trim-indent %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2016-09-27 11:47:28 +02:00
|
|
|
# remove trailing white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft x 1s^(\h+)$<ret> d }
|
2016-09-27 11:47:28 +02:00
|
|
|
}
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden fish-indent-on-char %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2016-09-27 12:08:42 +02:00
|
|
|
# align middle and end structures to start and indent when necessary
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft x<a-k>^\h*(else)$<ret><a-semicolon><a-?>^\h*(if)<ret>s\A|.\z<ret>1<a-&> }
|
|
|
|
try %{ execute-keys -draft x<a-k>^\h*(end)$<ret><a-semicolon><a-?>^\h*(begin|for|function|if|switch|while)<ret>s\A|.\z<ret>1<a-&> }
|
|
|
|
try %{ execute-keys -draft x<a-k>^\h*(case)$<ret><a-semicolon><a-?>^\h*(switch)<ret>s\A|.\z<ret>1<a-&> }
|
2014-07-03 17:50:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-10 12:15:57 +02:00
|
|
|
define-command -hidden fish-insert-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2019-03-19 17:51:42 +01:00
|
|
|
# copy '#' comment prefix and following white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x s ^\h*#\h* <ret> y jgh P }
|
2020-10-10 12:15:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define-command -hidden fish-indent-on-new-line %{
|
|
|
|
evaluate-commands -no-hooks -draft -itersel %{
|
2014-07-02 23:13:01 +02:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2019-03-19 17:51:42 +01:00
|
|
|
# cleanup trailing whitespaces from previous line
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x s \h+$ <ret> d }
|
2016-09-27 12:08:42 +02:00
|
|
|
# indent after start structure
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft kx<a-k>^\h*(begin|case|else|for|function|if|while)\b<ret>j<a-gt> }
|
2014-07-02 23:13:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 19:15:59 +01:00
|
|
|
}
|