diff --git a/rc/extra/elixir.kak b/rc/extra/elixir.kak new file mode 100644 index 000000000..a6a747e85 --- /dev/null +++ b/rc/extra/elixir.kak @@ -0,0 +1,76 @@ +# http://elixir-lang.org +# ---------------------- + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](ex|exs) %{ + set buffer filetype elixir +} + + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter -group / regions -default code elixir \ + double_string '"' (?|<-|<<|>>|=>) 0:builtin +add-highlighter -group /elixir/code regex \b(require|alias|use|import)\b 0:keyword +add-highlighter -group /elixir/code regex \b(__MODULE__|__DIR__|__ENV__|__CALLER__)\b 0:value +add-highlighter -group /elixir/code regex \b(def|defp|defmacro|defmacrop|defstruct|defmodule|defimpl|defprotocol|defoverridable)\b 0:keyword +add-highlighter -group /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 -group /elixir/code regex '@[\w_]+\b' 0:attribute +add-highlighter -group /elixir/code regex '\b\d+[\d_]*\b' 0:value + +# Commands +# ‾‾‾‾‾‾‾‾ + +def -hidden elixir-filter-around-selections %{ + # remove trailing white spaces + try %{ exec -draft -itersel s \h+$ d } +} + +def -hidden elixir-indent-on-new-line %{ + eval -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ exec -draft k s ^\h*\K--\h* y gh j P } + # preserve previous line indent + try %{ exec -draft \; K } + # indent after line ending with: + # try %{ exec -draft k x (do|else|->)$ & } + # filter previous line + try %{ exec -draft k : elixir-filter-around-selections } + # indent after lines ending with do or -> + try %{ exec -draft \\; k x ^.+(do|->)$ j } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group elixir-highlight global WinSetOption filetype=elixir %{ add-highlighter ref elixir } + +hook global WinSetOption filetype=elixir %{ + hook window InsertEnd .* -group elixir-hooks elixir-filter-around-selections + hook window InsertChar \n -group elixir-indent elixir-indent-on-new-line +} + +hook -group elixir-highlight global WinSetOption filetype=(?!elixir).* %{ remove-highlighter elixir } +