2017-02-13 01:25:53 +03:00
|
|
|
# http://elm-lang.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](elm) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype elm
|
2017-02-13 01:25:53 +03:00
|
|
|
}
|
|
|
|
|
2019-04-12 01:54:58 +03:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=elm %{
|
2019-03-14 00:00:59 +03:00
|
|
|
require-module elm
|
2019-04-12 01:54:58 +03:00
|
|
|
|
2019-10-16 12:19:43 +03:00
|
|
|
hook window ModeChange pop:insert:.* -group elm-trim-indent elm-trim-indent
|
2019-04-12 01:54:58 +03: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-14 00:00:59 +03:00
|
|
|
}
|
|
|
|
|
2019-11-11 02:11:36 +03:00
|
|
|
|
2019-03-14 00:00:59 +03:00
|
|
|
provide-module elm %[
|
|
|
|
|
2017-02-13 01:25:53 +03:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2019-10-02 05:44:54 +03:00
|
|
|
add-highlighter shared/elm regions
|
|
|
|
add-highlighter shared/elm/code default-region group
|
2019-11-11 02:12:17 +03:00
|
|
|
add-highlighter shared/elm/multiline_string region '"""' '"""' fill string
|
2019-10-02 05:44:54 +03: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 03:30:22 +03: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 09:46:23 +03:00
|
|
|
add-highlighter shared/elm/code/ regex "-?\b[0-9]*\.?[0-9]+" 0:value
|
2019-11-11 02:27:19 +03:00
|
|
|
add-highlighter shared/elm/code/ regex \B[-+<>!@#$%^&*=:/\\|]+\B 0:operator
|
2019-11-11 03:24:12 +03:00
|
|
|
add-highlighter shared/elm/code/ regex \b(import|exposing|as|module|port)\b 0:meta
|
2019-11-11 02:12:45 +03:00
|
|
|
add-highlighter shared/elm/code/ regex \b(type|alias|if|then|else|case|of|let|in|infix|_)\b) 0:keyword
|
2019-11-11 02:27:19 +03:00
|
|
|
add-highlighter shared/elm/code/ regex (?<![-+<>!@#$%^&*=:/\\|])(->|:|=|\|)(?![-+<>!@#$%^&*=:/\\|]) 0:keyword
|
2017-02-13 01:25:53 +03:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# http://elm-lang.org/docs/style-guide
|
|
|
|
|
2018-12-19 12:10:26 +03:00
|
|
|
define-command -hidden elm-trim-indent %{
|
2017-02-13 01:25:53 +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-02-13 01:25:53 +03:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden elm-indent-after "
|
2020-08-12 01:30:01 +03: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-13 01:25:53 +03:00
|
|
|
"
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden elm-indent-on-new-line %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-02-13 01:25:53 +03:00
|
|
|
# copy -- comments prefix and following white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P }
|
2017-02-13 01:25:53 +03:00
|
|
|
# preserve previous line indent
|
2019-10-22 12:02:06 +03:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2017-02-13 01:25:53 +03:00
|
|
|
# align to first clause
|
2019-10-22 12:02:06 +03: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-13 01:25:53 +03:00
|
|
|
# filter previous line
|
2018-12-19 12:10:26 +03:00
|
|
|
try %{ execute-keys -draft k : elm-trim-indent <ret> }
|
2017-02-13 01:25:53 +03:00
|
|
|
# indent after lines beginning with condition or ending with expression or =(
|
|
|
|
try %{ elm-indent-after }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-14 00:00:59 +03:00
|
|
|
]
|