From 9c9d56abf7b6c31dce8209c16f98a0d2afda99ed Mon Sep 17 00:00:00 2001 From: Alex Leferry 2 Date: Wed, 2 Jul 2014 23:13:01 +0200 Subject: [PATCH] add rc/fish.kak --- rc/fish.kak | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 rc/fish.kak diff --git a/rc/fish.kak b/rc/fish.kak new file mode 100644 index 00000000..9f46516e --- /dev/null +++ b/rc/fish.kak @@ -0,0 +1,70 @@ +# http://fishshell.com +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-fish %{ + set buffer filetype fish +} + +hook global BufCreate .*[.](fish) %{ + set buffer filetype fish +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / multi_region -default code fish \ + double_string (^|\h)" (?' $(printf '\Q%s\\E|' $(fish --command 'builtin --names' --command 'functions --names' | tr --delete ,)) } 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _fish_clean_around_selections %{ + eval -draft -itersel %{ + # trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _fish_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # cleanup previous line + try %{ exec -draft k : _fish_clean_around_selections } + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after (begin|for|function|if|switch|while) commands and add 'end' command + try %{ exec -draft k x (begin|for|function|if|switch|while) x y p j a end k } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=fish %{ + addhl ref fish + + hook window InsertEnd .* -group fish-hooks _fish_clean_around_selections + 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 +}