1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-18 17:02:06 +03:00
kakoune/rc/filetype/fish.kak

81 lines
3.1 KiB
Plaintext
Raw Normal View History

2014-07-03 01:13:01 +04:00
# http://fishshell.com
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](fish) %{
set-option buffer filetype fish
2014-07-03 01:13:01 +04:00
}
2019-04-11 02:48:46 +03:00
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=fish %{
2019-03-13 21:15:59 +03:00
require-module fish
2019-04-11 02:48:46 +03:00
hook window InsertChar .* -group fish-indent fish-indent-on-char
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 21:15:59 +03:00
}
2019-04-11 02:48:46 +03: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 21:15:59 +03:00
provide-module fish %{
2014-07-03 01:13:01 +04:00
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
add-highlighter shared/fish regions
add-highlighter shared/fish/code default-region group
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
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
add-highlighter shared/fish/code/ regex (\$\w+)|(\{\$\w+\}) 0:variable
2014-07-03 01:13:01 +04:00
# Command names are collected using `builtin --names` and 'eval' from `functions --names`
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
# ‾‾‾‾‾‾‾‾
define-command -hidden fish-trim-indent %{
evaluate-commands -no-hooks -draft -itersel %{
# remove trailing white spaces
2019-03-19 19:51:42 +03:00
try %{ execute-keys -draft <a-x> 1s^(\h+)$<ret> d }
}
2014-07-03 01:13:01 +04:00
}
define-command -hidden fish-indent-on-char %{
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
2019-03-19 19:51:42 +03:00
try %{ execute-keys -draft <a-x><a-k>^\h*(else)$<ret><a-\;><a-?>^\h*(if)<ret>s\A|.\z<ret>1<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>1<a-&> }
try %{ execute-keys -draft <a-x><a-k>^\h*(case)$<ret><a-\;><a-?>^\h*(switch)<ret>s\A|.\z<ret>1<a-&> }
}
}
define-command -hidden fish-indent-on-new-line %{
evaluate-commands -no-hooks -draft -itersel %{
2019-03-19 19:51:42 +03:00
# copy '#' comment prefix and following white spaces
try %{ execute-keys -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
2014-07-03 01:13:01 +04:00
# preserve previous line indent
2019-03-19 19:51:42 +03:00
try %{ execute-keys -draft \; K <a-&> }
# cleanup trailing whitespaces from previous line
try %{ execute-keys -draft k <a-x> s \h+$ <ret> d }
2016-09-27 13:08:42 +03:00
# indent after start structure
2019-03-19 19:51:42 +03:00
try %{ execute-keys -draft k<a-x><a-k>^\h*(begin|case|else|for|function|if|while)\b<ret>j<a-gt> }
2014-07-03 01:13:01 +04:00
}
}
2019-03-13 21:15:59 +03:00
}