2017-05-05 19:01:07 +03:00
|
|
|
# http://elixir-lang.org
|
|
|
|
# ----------------------
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](ex|exs) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype elixir
|
2017-05-05 19:01:07 +03:00
|
|
|
}
|
|
|
|
|
2020-05-03 14:54:48 +03:00
|
|
|
hook global BufCreate .*[.]html[.]l?eex %{
|
|
|
|
set-option buffer filetype eex
|
|
|
|
}
|
|
|
|
|
2019-04-10 06:54:19 +03:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=elixir %{
|
2019-03-14 00:00:59 +03:00
|
|
|
require-module elixir
|
2019-04-10 06:54:19 +03:00
|
|
|
|
2019-10-16 12:19:43 +03:00
|
|
|
hook window ModeChange pop:insert:.* -group elixir-trim-indent elixir-trim-indent
|
2019-04-10 06:54:19 +03:00
|
|
|
hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line
|
2021-06-05 21:59:22 +03:00
|
|
|
hook window InsertChar \n -group elixir-insert elixir-insert-on-new-line
|
2019-04-10 06:54:19 +03:00
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elixir-.+ }
|
2019-03-14 00:00:59 +03:00
|
|
|
}
|
|
|
|
|
2019-04-10 06:54:19 +03:00
|
|
|
hook -group elixir-highlight global WinSetOption filetype=elixir %{
|
|
|
|
add-highlighter window/elixir ref elixir
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elixir }
|
|
|
|
}
|
|
|
|
|
2020-05-03 14:54:48 +03:00
|
|
|
hook global WinSetOption filetype=eex %{
|
|
|
|
require-module eex
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window eex-.+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group eex-highlight global WinSetOption filetype=eex %{
|
|
|
|
add-highlighter window/eex ref eex
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/eex }
|
|
|
|
}
|
|
|
|
|
|
|
|
provide-module eex %{
|
|
|
|
require-module html
|
|
|
|
require-module elixir
|
|
|
|
|
|
|
|
add-highlighter shared/eex regions
|
|
|
|
add-highlighter shared/eex/html default-region ref html
|
2020-05-03 14:54:51 +03:00
|
|
|
add-highlighter shared/eex/comment region '<%#' '%>' fill comment
|
|
|
|
add-highlighter shared/eex/quote region '<%%' '%>' ref html
|
2020-05-03 14:54:50 +03:00
|
|
|
add-highlighter shared/eex/code region '<%=?' '%>' ref elixir
|
2020-05-03 14:54:48 +03:00
|
|
|
}
|
2019-04-10 06:54:19 +03:00
|
|
|
|
2019-03-14 00:00:59 +03:00
|
|
|
provide-module elixir %[
|
2017-05-05 19:01:07 +03:00
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 12:53:35 +03:00
|
|
|
add-highlighter shared/elixir regions
|
|
|
|
add-highlighter shared/elixir/code default-region group
|
2020-05-03 14:54:48 +03:00
|
|
|
add-highlighter shared/elixir/double_string region -match-capture ("""|") (?<!\\)(?:\\\\)*("""|") regions
|
|
|
|
add-highlighter shared/elixir/single_string region "'" "(?<!\\)(?:\\\\)*'" fill string
|
|
|
|
add-highlighter shared/elixir/comment region '#' '$' fill comment
|
|
|
|
|
|
|
|
add-highlighter shared/elixir/leex region -match-capture '~L("""|")' '(?<!\\)(?:\\\\)*("""|")' ref eex
|
2017-05-05 19:01:07 +03:00
|
|
|
|
2018-07-01 12:53:35 +03:00
|
|
|
add-highlighter shared/elixir/double_string/base default-region fill string
|
2018-07-02 13:59:12 +03:00
|
|
|
add-highlighter shared/elixir/double_string/interpolation region -recurse \{ \Q#{ \} fill builtin
|
2018-07-01 12:53:35 +03:00
|
|
|
|
|
|
|
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 19:01:07 +03:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 12:10:26 +03:00
|
|
|
define-command -hidden elixir-trim-indent %{
|
2017-05-05 19:01:07 +03:00
|
|
|
# remove trailing white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
|
2017-05-05 19:01:07 +03:00
|
|
|
}
|
|
|
|
|
2021-06-05 21:59:22 +03:00
|
|
|
define-command -hidden elixir-insert-on-new-line %[
|
|
|
|
evaluate-commands -no-hooks -draft -itersel %[
|
2021-06-05 22:05:45 +03:00
|
|
|
# copy '#' comment prefix and following white spaces
|
2021-06-06 11:29:51 +03:00
|
|
|
try %{ execute-keys -draft k <a-x> s ^\h*\K#\h* <ret> y jgi P }
|
2021-06-05 21:59:22 +03:00
|
|
|
# wisely add end structure
|
|
|
|
evaluate-commands -save-regs x %[
|
|
|
|
try %{ execute-keys -draft k <a-x> s ^ \h + <ret> \" x y } catch %{ reg x '' }
|
|
|
|
try %[
|
|
|
|
evaluate-commands -draft %[
|
|
|
|
# Check if previous line opens a block
|
|
|
|
execute-keys -draft k<a-x> <a-k>^<c-r>x(.+\bdo$)<ret>
|
|
|
|
# Check that we do not already have an end for this indent level which is first set via `elixir-indent-on-new-line` hook
|
|
|
|
execute-keys -draft }i J <a-x> <a-K> ^<c-r>x(end|else)[^0-9A-Za-z_!?]<ret>
|
|
|
|
]
|
|
|
|
execute-keys -draft o<c-r>xend<esc> # insert a new line with containing end
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
2021-04-17 11:17:01 +03:00
|
|
|
|
|
|
|
define-command -hidden elixir-indent-on-new-line %{
|
|
|
|
evaluate-commands -draft -itersel %{
|
2017-05-05 19:01:07 +03:00
|
|
|
# preserve previous line indent
|
2019-10-22 12:02:06 +03:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2019-03-14 00:00:59 +03:00
|
|
|
# indent after line ending with:
|
2021-04-17 12:51:25 +03:00
|
|
|
# try %{ execute-keys -draft k x <a-k> (\bdo|\belse|->)$ <ret> & }
|
|
|
|
# filter previous line
|
2018-12-19 12:10:26 +03:00
|
|
|
try %{ execute-keys -draft k : elixir-trim-indent <ret> }
|
2017-05-05 19:01:07 +03:00
|
|
|
# indent after lines ending with do or ->
|
2020-08-12 01:30:01 +03:00
|
|
|
try %{ execute-keys -draft <semicolon> k x <a-k> ^.+(\bdo|->)$ <ret> j <a-gt> }
|
2017-05-05 19:01:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 00:00:59 +03:00
|
|
|
]
|