# http://moonscript.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](moon) %{ set buffer filetype moon } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter -group / regions -default code moon \ double_string '"' (? # remove trailing white spaces try %{ exec -draft s \h + $ d } } } def -hidden moon-indent-on-char %{ eval -draft -itersel %{ # align _else_ statements to start try %{ exec -draft ^ \h * (else(if)?) $ ^ \h * (if|unless|when) s \A | \z \' } # align _when_ to _switch_ then indent try %{ exec -draft ^ \h * (when) $ ^ \h * (switch) s \A | \z \' \' } # align _catch_ and _finally_ to _try_ try %{ exec -draft ^ \h * (catch|finally) $ ^ \h * (try) s \A | \z \' } } } def -hidden moon-indent-on-new-line %{ eval -draft -itersel %{ # copy -- comment prefix and following white spaces try %{ exec -draft k s ^ \h * \K -- \h * y gh j P } # preserve previous line indent try %{ exec -draft \; K } # filter previous line try %{ exec -draft k : moon-filter-around-selections } # indent after start structure try %{ exec -draft k ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ j } # deindent after return statements try %{ exec -draft k ^ \h * (break|return) \b j } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group moon-highlight global WinSetOption filetype=moon %{ add-highlighter ref moon } hook global WinSetOption filetype=moon %{ hook window InsertEnd .* -group moon-hooks moon-filter-around-selections hook window InsertChar .* -group moon-indent moon-indent-on-char hook window InsertChar \n -group moon-indent moon-indent-on-new-line alias window alt moon-alternative-file } hook -group moon-highlight global WinSetOption filetype=(?!moon).* %{ remove-highlighter moon } hook global WinSetOption filetype=(?!moon).* %{ remove-hooks window moon-indent remove-hooks window moon-hooks unalias window alt moon-alternative-file }