1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-01 08:23:05 +03:00
kakoune/rc/base/fish.kak

88 lines
3.4 KiB
Plaintext
Raw Normal View History

2014-07-03 01:13:01 +04:00
# http://fishshell.com
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](fish) %{
set buffer filetype fish
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
2017-01-04 03:07:45 +03:00
add-highlighter -group / regions -default code fish \
double_string '"' (?<!\\)(\\\\)*" '' \
single_string "'" "'" '' \
comment '#' '$' ''
2014-07-03 01:13:01 +04:00
2017-01-04 03:07:45 +03:00
add-highlighter -group /fish/double_string fill string
add-highlighter -group /fish/double_string regex (\$\w+)|(\{\$\w+\}) 0:variable
2017-01-04 03:07:45 +03:00
add-highlighter -group /fish/single_string fill string
add-highlighter -group /fish/comment fill comment
2014-07-03 01:13:01 +04:00
add-highlighter -group /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`
2017-01-04 03:07:45 +03:00
add-highlighter -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-03 01:13:01 +04:00
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden fish-filter-around-selections %{
2016-09-27 12:48:46 +03:00
eval -no-hooks -draft -itersel %{
# remove trailing white spaces
try %{ exec -draft <a-x>s\h+$<ret>d }
}
2014-07-03 01:13:01 +04:00
}
def -hidden fish-indent-on-char %{
2016-09-27 12:48:46 +03:00
eval -no-hooks -draft -itersel %{
2016-09-27 13:08:42 +03: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> }
}
}
def -hidden fish-indent-on-new-line %{
2016-09-27 12:48:46 +03:00
eval -no-hooks -draft -itersel %{
2014-07-03 01:13:01 +04:00
# preserve previous line indent
2016-09-27 12:36:43 +03:00
try %{ exec -draft <space>K<a-&> }
# filter previous line
try %{ exec -draft k:fish-filter-around-selections<ret> }
2016-09-27 13:08:42 +03:00
# indent after start structure
try %{ exec -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
}
}
def -hidden fish-insert-on-new-line %{
2016-09-27 13:08:42 +03:00
eval -no-hooks -draft -itersel %{
# copy _#_ comment prefix and following white spaces
try %{ exec -draft k<a-x>s^\h*\K#\h*<ret>yjp }
2016-09-27 13:08:42 +03:00
# wisely add end structure
eval -save-regs x %{
try %{ exec -draft k<a-x>s^\h+<ret>"xy } catch %{ reg x '' }
try %{ exec -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
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
2017-01-04 03:07:45 +03:00
hook -group fish-highlight global WinSetOption filetype=fish %{ add-highlighter ref fish }
2014-07-03 01:13:01 +04:00
hook global WinSetOption filetype=fish %{
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
2014-07-03 01:13:01 +04:00
}
2017-01-04 03:07:45 +03:00
hook -group fish-highlight global WinSetOption filetype=(?!fish).* %{ remove-highlighter fish }
2014-07-03 01:13:01 +04:00
hook global WinSetOption filetype=(?!fish).* %{
2017-01-04 03:07:45 +03:00
remove-hooks window fish-indent
remove-hooks window fish-insert
2014-07-03 01:13:01 +04:00
}