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
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=elm %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module elm
|
2019-04-12 00:54:58 +02:00
|
|
|
|
|
|
|
hook window ModeChange insert:.* -group elm-trim-indent elm-trim-indent
|
|
|
|
hook window InsertChar \n -group elm-indent elm-indent-on-new-line
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elm-.+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group elm-highlight global WinSetOption filetype=elm %{
|
|
|
|
add-highlighter window/elm ref elm
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elm }
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
provide-module elm %[
|
|
|
|
|
2017-02-12 23:25:53 +01:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2019-10-02 04:44:54 +02:00
|
|
|
add-highlighter shared/elm regions
|
|
|
|
add-highlighter shared/elm/code default-region group
|
|
|
|
add-highlighter shared/elm/string region '"' (?<!\\)(\\\\)*" fill string
|
|
|
|
add-highlighter shared/elm/line_comment region (--) $ fill comment
|
|
|
|
add-highlighter shared/elm/comment region -recurse \{- \{- -\} fill comment
|
|
|
|
|
2019-10-02 08:46:23 +02:00
|
|
|
add-highlighter shared/elm/code/ regex \b([A-Z]+[^\s]*)\b 0:type
|
|
|
|
add-highlighter shared/elm/code/ regex \b([a-z]+[^\s]*)\b 0:variable
|
|
|
|
add-highlighter shared/elm/code/ regex \b(^[a-z]+[^\s]*)\b 0:function
|
|
|
|
add-highlighter shared/elm/code/ regex "-?\b[0-9]*\.?[0-9]+" 0:value
|
|
|
|
add-highlighter shared/elm/code/ regex \B(\+|\+\+|\*|/|//|-|=|==|&&|\|\||<\||\|>)\B 0:operator
|
|
|
|
add-highlighter shared/elm/code/ regex \b(import|exposing|as|module|where)\b 0:meta
|
|
|
|
add-highlighter shared/elm/code/ regex (\b(type|alias|if|then|else|case|of|let|in|infix|_)\b)|(\B(->|:)\B) 0:keyword
|
2017-02-12 23:25:53 +01:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# http://elm-lang.org/docs/style-guide
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden elm-trim-indent %{
|
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
|
2018-12-19 10:10:26 +01:00
|
|
|
try %{ execute-keys -draft k : elm-trim-indent <ret> }
|
2017-02-12 23:25:53 +01:00
|
|
|
# indent after lines beginning with condition or ending with expression or =(
|
|
|
|
try %{ elm-indent-after }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
]
|