2017-02-12 23:25:53 +01:00
|
|
|
# http://elm-lang.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](elm) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype elm
|
2017-02-12 23:25:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/ regions -default code elm \
|
2017-02-12 23:25:53 +01:00
|
|
|
string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
comment (--) $ '' \
|
|
|
|
comment \{- -\} \{- \
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/elm/string fill string
|
|
|
|
add-highlighter shared/elm/comment fill comment
|
2017-02-12 23:25:53 +01:00
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
add-highlighter shared/elm/code regex \b(import|exposing|as|module|where)\b 0:meta
|
|
|
|
add-highlighter shared/elm/code regex \b(True|False)\b 0:value
|
|
|
|
add-highlighter shared/elm/code regex \b(if|then|else|case|of|let|in|type|port|alias)\b 0:keyword
|
|
|
|
add-highlighter shared/elm/code regex \b(Array|Bool|Char|Float|Int|String)\b 0:type
|
2017-02-12 23:25:53 +01:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# http://elm-lang.org/docs/style-guide
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden elm-filter-around-selections %{
|
2017-02-12 23:25:53 +01: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-02-12 23:25:53 +01:00
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden elm-indent-after "
|
2017-11-03 09:09:45 +01:00
|
|
|
execute-keys -draft \\; k x <a-k> ^\\h*(if)|(case\\h+[\\w']+\\h+of|let|in|\\{\\h+\\w+|\\w+\\h+->|[=(])$ <ret> j <a-gt>
|
2017-02-12 23:25:53 +01:00
|
|
|
"
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden elm-indent-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-02-12 23:25:53 +01: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-02-12 23:25:53 +01:00
|
|
|
# preserve previous line indent
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \; K <a-&> }
|
2017-02-12 23:25:53 +01:00
|
|
|
# align to first clause
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|let)\h+\K.* <ret> s \A|.\z <ret> & }
|
2017-02-12 23:25:53 +01:00
|
|
|
# filter previous line
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft k : elm-filter-around-selections <ret> }
|
2017-02-12 23:25:53 +01:00
|
|
|
# indent after lines beginning with condition or ending with expression or =(
|
|
|
|
try %{ elm-indent-after }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group elm-highlight global WinSetOption filetype=elm %{ add-highlighter window ref elm }
|
2017-02-12 23:25:53 +01:00
|
|
|
|
|
|
|
hook global WinSetOption filetype=elm %{
|
2018-01-21 00:35:05 +01:00
|
|
|
hook window ModeChange insert:.* -group elm-hooks elm-filter-around-selections
|
2017-02-12 23:25:53 +01:00
|
|
|
hook window InsertChar \n -group elm-indent elm-indent-on-new-line
|
|
|
|
}
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group elm-highlight global WinSetOption filetype=(?!elm).* %{ remove-highlighter window/elm }
|
2017-02-12 23:25:53 +01:00
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!elm).* %{
|
|
|
|
remove-hooks window elm-indent
|
|
|
|
remove-hooks window elm-hooks
|
|
|
|
}
|