# http://moonscript.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](moon) %{ set-option buffer filetype moon } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/moon regions add-highlighter shared/moon/code default-region group add-highlighter shared/moon/double_string region '"' (? # remove trailing white spaces try %{ execute-keys -draft s \h + $ d } } } define-command -hidden moon-indent-on-char %{ evaluate-commands -draft -itersel %{ # align _else_ statements to start try %{ execute-keys -draft ^ \h * (else(if)?) $ ^ \h * (if|unless|when) s \A | \z ) } # align _when_ to _switch_ then indent try %{ execute-keys -draft ^ \h * (when) $ ^ \h * (switch) s \A | \z ) ) } # align _catch_ and _finally_ to _try_ try %{ execute-keys -draft ^ \h * (catch|finally) $ ^ \h * (try) s \A | \z ) } } } define-command -hidden moon-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 : moon-filter-around-selections } # indent after start structure try %{ execute-keys -draft k ^ \h * (class|else(if)?|for|if|switch|unless|when|while|with) \b | ([:=]|[-=]>) $ j } # deindent after return statements try %{ execute-keys -draft k ^ \h * (break|return) \b j } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group moon-highlight global WinSetOption filetype=moon %{ add-highlighter window/moon ref moon hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/moon } } hook global WinSetOption filetype=moon %{ hook window ModeChange insert:.* -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 -once -always window WinSetOption filetype=.* %{ remove-hooks window moon-.+ unalias window alt moon-alternative-file } }