# http://elixir-lang.org # ---------------------- # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.](ex|exs) %{ set-option buffer filetype elixir } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=elixir %{ require-module elixir hook window ModeChange pop:insert:.* -group elixir-trim-indent elixir-trim-indent hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elixir-.+ } } hook -group elixir-highlight global WinSetOption filetype=elixir %{ add-highlighter window/elixir ref elixir hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elixir } } provide-module elixir %[ # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/elixir regions add-highlighter shared/elixir/code default-region group add-highlighter shared/elixir/double_string region '"' (?|<-|<<|>>|=>) 0:builtin add-highlighter shared/elixir/code/ regex \b(require|alias|use|import)\b 0:keyword add-highlighter shared/elixir/code/ regex \b(__MODULE__|__DIR__|__ENV__|__CALLER__)\b 0:value add-highlighter shared/elixir/code/ regex \b(def|defp|defmacro|defmacrop|defstruct|defmodule|defimpl|defprotocol|defoverridable)\b 0:keyword add-highlighter shared/elixir/code/ regex \b(fn|do|end|when|case|if|else|unless|var!|for|cond|quote|unquote|receive|with|raise|reraise|try|catch)\b 0:keyword add-highlighter shared/elixir/code/ regex '@[\w_]+\b' 0:attribute add-highlighter shared/elixir/code/ regex '\b\d+[\d_]*\b' 0:value # Commands # ‾‾‾‾‾‾‾‾ define-command -hidden elixir-trim-indent %{ # remove trailing white spaces try %{ execute-keys -draft -itersel s \h+$ d } } define-command -hidden elixir-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 } # indent after line ending with: # try %{ execute-keys -draft k x (do|else|->)$ & } # filter previous line try %{ execute-keys -draft k : elixir-trim-indent } # indent after lines ending with do or -> try %{ execute-keys -draft \\; k x ^.+(do|->)$ j } } } ]