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/coffee.kak | 92 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 autoload/filetype/coffee.kak (limited to 'autoload/filetype/coffee.kak') diff --git a/autoload/filetype/coffee.kak b/autoload/filetype/coffee.kak new file mode 100644 index 0000000..c9ee330 --- /dev/null +++ b/autoload/filetype/coffee.kak @@ -0,0 +1,92 @@ +# http://coffeescript.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](coffee) %{ + set-option buffer filetype coffee +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=coffee %{ + require-module coffee + + hook window ModeChange pop:insert:.* -group coffee-trim-indent coffee-trim-indent + hook window InsertChar \n -group coffee-insert coffee-insert-on-new-line + hook window InsertChar \n -group coffee-indent coffee-indent-on-new-line + + hook -once -always window WinSetOption filetype=.* %{ remove-hooks window coffee-.+ } +} + +hook -group coffee-highlight global WinSetOption filetype=coffee %{ + add-highlighter window/coffee ref coffee + hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/coffee } +} + + +provide-module coffee %[ + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter shared/coffee regions +add-highlighter shared/coffee/code default-region group +add-highlighter shared/coffee/single_string region "'" "'" fill string +add-highlighter shared/coffee/single_string_alt region "'''" "'''" fill string +add-highlighter shared/coffee/double_string region '"' (? d } + } +} + +define-command -hidden coffee-insert-on-new-line %{ + evaluate-commands -draft -itersel %{ + # copy '#' comment prefix and following white spaces + try %{ execute-keys -draft k x s '^\h*\K#\h*' y gh j P } + } +} + +define-command -hidden coffee-indent-on-new-line %{ + evaluate-commands -draft -itersel %{ + # preserve previous line indent + try %{ execute-keys -draft K } + # filter previous line + try %{ execute-keys -draft k : coffee-trim-indent } + # indent after start structure + try %{ execute-keys -draft k x ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ j } + } +} + +] -- cgit v1.2.3