# http://elm-lang.org # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](elm) %{ set-option buffer filetype elm } # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/elm regions add-highlighter shared/elm/code default-region group add-highlighter shared/elm/string region '"' (? s \h+$ d } } define-command -hidden elm-indent-after " execute-keys -draft \\; k x ^\\h*(if)|(case\\h+[\\w']+\\h+of|let|in|\\{\\h+\\w+|\\w+\\h+->|[=(])$ j " define-command -hidden elm-indent-on-new-line %{ evaluate-commands -draft -itersel %{ # copy -- comments 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 } # align to first clause try %{ execute-keys -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|let)\h+\K.* s \A|.\z & } # filter previous line try %{ execute-keys -draft k : elm-filter-around-selections } # indent after lines beginning with condition or ending with expression or =( try %{ elm-indent-after } } } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook -group elm-highlight global WinSetOption filetype=elm %{ add-highlighter window/elm ref elm hook -once -always window WinSetOption filetype=(?!elm).* %{ remove-highlighter window/elm } } hook global WinSetOption filetype=elm %{ hook window ModeChange insert:.* -group elm-hooks elm-filter-around-selections hook window InsertChar \n -group elm-indent elm-indent-on-new-line hook -once -always window WinSetOption filetype=(?!elm).* %{ remove-hooks window elm-.+ } }