diff --git a/rc/coffee.kak b/rc/coffee.kak new file mode 100644 index 00000000..2d2cc420 --- /dev/null +++ b/rc/coffee.kak @@ -0,0 +1,87 @@ +# http://coffeescript.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufSetOption mimetype=text/x-coffee %{ + set buffer filetype coffee +} + +hook global BufCreate .*[.](coffee) %{ + set buffer filetype coffee +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +addhl -group / regions -default code coffee \ + double_string '"""' '"""' '' \ + single_string "'''" "'''" '' \ + comment '###' '###' '' \ + regex '///' ///[gimy]* '' \ + double_string '"' (? 0:type +addhl -group /coffee/code regex \<(document|false|no|null|off|on|parent|self|this|true|undefined|window|yes)\> 0:value +addhl -group /coffee/code regex \<(and|is|isnt|not|or)\> 0:operator +addhl -group /coffee/code regex \<(break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|function|if|implements|import|in|instanceof|interface|let|native|new|package|private|protected|public|return|static|super|switch|throw|try|typeof|var|void|while|with|yield)\> 0:keyword + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden _coffee_filter_around_selections %{ + eval -draft -itersel %{ + exec + # remove trailing white spaces + try %{ exec -draft s \h+$ d } + } +} + +def -hidden _coffee_indent_on_new_line %{ + eval -draft -itersel %{ + # preserve previous line indent + try %{ exec -draft K } + # filter previous line + try %{ exec -draft k : _coffee_filter_around_selections } + # copy '#' comment prefix and following white spaces + try %{ exec -draft k x s ^\h*\K#\h* y j p } + # indent after lines beginning with token and ending with -> + try %_ exec -draft k x ^\h*(case|catch|class|else|finally|for|function|if|switch|try|while|with)|(->)$ j _ + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook global WinSetOption filetype=coffee %{ + addhl ref coffee + + hook window InsertEnd .* -group coffee-hooks _coffee_filter_around_selections + hook window InsertChar \n -group coffee-indent _coffee_indent_on_new_line +} + +hook global WinSetOption filetype=(?!coffee).* %{ + rmhl coffee + rmhooks window coffee-indent + rmhooks window coffee-hooks +}