# http://coffeescript.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](coffee) %{ set-option buffer filetype coffee } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/ regions -default code coffee \ double_string '"""' '"""' '' \ single_string "'''" "'''" '' \ comment '###' '###' '' \ regex '///' ///[gimy]* '' \ double_string '"' (? # remove trailing white spaces try %{ execute-keys -draft s \h + $ d } } } define-command -hidden coffee-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # copy '#' comment prefix and following white spaces try %{ execute-keys -draft k s '^\h*\K#\h*' y gh j P } # preserve previous line indent try %{ execute-keys -draft \; K } # filter previous line try %{ execute-keys -draft k : coffee-filter-around-selections } # indent after start structure try %{ execute-keys -draft k ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ j } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group coffee-highlight global WinSetOption filetype=coffee %{ add-highlighter window ref coffee } hook global WinSetOption filetype=coffee %{ hook window InsertEnd .* -group coffee-hooks coffee-filter-around-selections hook window InsertChar \n -group coffee-indent coffee-indent-on-new-line } hook -group coffee-highlight global WinSetOption filetype=(?!coffee).* %{ remove-highlighter window/coffee } hook global WinSetOption filetype=(?!coffee).* %{ remove-hooks window coffee-indent remove-hooks window coffee-hooks }