From 904cec3c4a329cf89fc3219d359239910d61f3f6 Mon Sep 17 00:00:00 2001 From: thing1 Date: Tue, 28 Jan 2025 09:14:32 +0000 Subject: init commit --- autoload/filetype/fish.kak | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 autoload/filetype/fish.kak (limited to 'autoload/filetype/fish.kak') diff --git a/autoload/filetype/fish.kak b/autoload/filetype/fish.kak new file mode 100644 index 0000000..0bfcc4f --- /dev/null +++ b/autoload/filetype/fish.kak @@ -0,0 +1,87 @@ +# http://fishshell.com +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](fish) %{ + set-option buffer filetype fish +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=fish %{ + require-module fish + + hook window ModeChange pop:insert:.* -group fish-trim-indent fish-trim-indent + 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 + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fish-.+ } +} + +hook -group fish-highlight global WinSetOption filetype=fish %{ + add-highlighter window/fish ref fish + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fish } +} + + +provide-module fish %{ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/fish regions +add-highlighter shared/fish/code default-region group +add-highlighter shared/fish/double_string region (? d } + } +} + +define-command -hidden fish-indent-on-char %{ + evaluate-commands -no-hooks -draft -itersel %{ + # align middle and end structures to start and indent when necessary + try %{ execute-keys -draft x^\h*(else)$^\h*(if)s\A|.\z1 } + try %{ execute-keys -draft x^\h*(end)$^\h*(begin|for|function|if|switch|while)s\A|.\z1 } + try %{ execute-keys -draft x^\h*(case)$^\h*(switch)s\A|.\z1 } + } +} + +define-command -hidden fish-insert-on-new-line %{ + evaluate-commands -no-hooks -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k x s ^\h*#\h* y jgh P } + } +} + +define-command -hidden fish-indent-on-new-line %{ + evaluate-commands -no-hooks -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # cleanup trailing whitespaces from previous line + try %{ execute-keys -draft k x s \h+$ d } + # indent after start structure + try %{ execute-keys -draft kx^\h*(begin|case|else|for|function|if|while)\bj } + } +} + +} -- cgit v1.2.3