2017-05-05 18:01:07 +02:00
|
|
|
# http://elixir-lang.org
|
|
|
|
# ----------------------
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](ex|exs) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype elixir
|
2017-05-05 18:01:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/elixir regions
|
|
|
|
add-highlighter shared/elixir/code default-region group
|
|
|
|
add-highlighter shared/elixir/double_string region '"' (?<!\\)(\\\\)*" '' regions
|
|
|
|
add-highlighter shared/elixir/triple_string region '"""' (?<!\\)(\\\\)*""" '' ref shared/elixir/double_string
|
|
|
|
add-highlighter shared/elixir/single_string region "'" (?<!\\)(\\\\)*' '' fill string
|
|
|
|
add-highlighter shared/elixir/comment region '#' '$' '' fill comment
|
2017-05-05 18:01:07 +02:00
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/elixir/double_string/base default-region fill string
|
|
|
|
add-highlighter shared/elixir/double_string/interpolation region \Q#{ \} \{ fill builtin
|
|
|
|
|
|
|
|
add-highlighter shared/elixir/code/ regex ':[\w_]+\b' 0:type
|
|
|
|
add-highlighter shared/elixir/code/ regex '[\w_]+:' 0:type
|
|
|
|
add-highlighter shared/elixir/code/ regex '[A-Z][\w_]+\b' 0:module
|
|
|
|
add-highlighter shared/elixir/code/ regex '(:[\w_]+)(\.)' 1:module
|
|
|
|
add-highlighter shared/elixir/code/ regex '\b_\b' 0:default
|
|
|
|
add-highlighter shared/elixir/code/ regex '\b_[\w_]+\b' 0:default
|
|
|
|
add-highlighter shared/elixir/code/ regex '~[a-zA-Z]\(.*\)' 0:string
|
|
|
|
add-highlighter shared/elixir/code/ regex \b(true|false|nil)\b 0:value
|
|
|
|
add-highlighter shared/elixir/code/ regex (->|<-|<<|>>|=>) 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
|
2017-05-05 18:01:07 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden elixir-filter-around-selections %{
|
2017-05-05 18:01:07 +02:00
|
|
|
# remove trailing white spaces
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
|
2017-05-05 18:01:07 +02:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden elixir-indent-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-05-05 18:01:07 +02:00
|
|
|
# copy -- comments prefix and following white spaces
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
|
2017-05-05 18:01:07 +02:00
|
|
|
# preserve previous line indent
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \; K <a-&> }
|
2017-05-05 18:01:07 +02:00
|
|
|
# indent after line ending with:
|
2017-11-03 09:09:45 +01:00
|
|
|
# try %{ execute-keys -draft k x <a-k> (do|else|->)$ <ret> & }
|
2017-05-05 18:01:07 +02:00
|
|
|
# filter previous line
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft k : elixir-filter-around-selections <ret> }
|
2017-05-05 18:01:07 +02:00
|
|
|
# indent after lines ending with do or ->
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \\; k x <a-k> ^.+(do|->)$ <ret> j <a-gt> }
|
2017-05-05 18:01:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
hook -group elixir-highlight global WinSetOption filetype=elixir %{ add-highlighter window/elixir ref elixir }
|
2017-05-05 18:01:07 +02:00
|
|
|
|
|
|
|
hook global WinSetOption filetype=elixir %{
|
2018-01-21 00:35:05 +01:00
|
|
|
hook window ModeChange insert:.* -group elixir-hooks elixir-filter-around-selections
|
2017-05-05 18:01:07 +02:00
|
|
|
hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line
|
|
|
|
}
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group elixir-highlight global WinSetOption filetype=(?!elixir).* %{ remove-highlighter window/elixir }
|
2017-05-05 18:01:07 +02:00
|
|
|
|