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
|
|
|
|
2019-10-16 11:19:43 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group elm-trim-indent elm-trim-indent
|
2019-04-12 00:54:58 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-11-11 00:11:36 +01:00
|
|
|
|
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
|
2019-11-11 00:12:17 +01:00
|
|
|
add-highlighter shared/elm/multiline_string region '"""' '"""' fill string
|
2019-10-02 04:44:54 +02:00
|
|
|
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-11-11 01:30:22 +01:00
|
|
|
add-highlighter shared/elm/code/ regex \b[A-Z]\w*\b 0:type
|
|
|
|
add-highlighter shared/elm/code/ regex \b[a-z]\w*\b 0:variable
|
|
|
|
add-highlighter shared/elm/code/ regex ^[a-z]\w*\b 0:function
|
2019-10-02 08:46:23 +02:00
|
|
|
add-highlighter shared/elm/code/ regex "-?\b[0-9]*\.?[0-9]+" 0:value
|
2019-11-11 00:27:19 +01:00
|
|
|
add-highlighter shared/elm/code/ regex \B[-+<>!@#$%^&*=:/\\|]+\B 0:operator
|
2019-11-11 01:24:12 +01:00
|
|
|
add-highlighter shared/elm/code/ regex \b(import|exposing|as|module|port)\b 0:meta
|
2019-11-11 00:12:45 +01:00
|
|
|
add-highlighter shared/elm/code/ regex \b(type|alias|if|then|else|case|of|let|in|infix|_)\b) 0:keyword
|
2019-11-11 00:27:19 +01:00
|
|
|
add-highlighter shared/elm/code/ regex (?<![-+<>!@#$%^&*=:/\\|])(->|:|=|\|)(?![-+<>!@#$%^&*=:/\\|]) 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 "
|
2020-08-12 00:30:01 +02:00
|
|
|
execute-keys -draft <semicolon> k x <a-k> ^\\h*if|[=(]$|\\b(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
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2017-02-12 23:25:53 +01:00
|
|
|
# align to first clause
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> 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
|
|
|
]
|