diff options
| author | Maxime Coste <mawww@kakoune.org> | 2017-02-13 20:28:29 +0000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2017-02-13 20:28:29 +0000 |
| commit | 55bd3b7949f4a2227313133f7104f8d9ffde0d6c (patch) | |
| tree | 4cc82adb54508bd52e4859b7a076e66a83b4a87e | |
| parent | f6ce3f7edc8640d0349293347a47c12fb0f60450 (diff) | |
| parent | ec77784d98d0966521f917557fe129e4d22ec958 (diff) | |
Merge remote-tracking branch 'tmiller/add-elm-support'
| -rw-r--r-- | rc/extra/elm.kak | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/rc/extra/elm.kak b/rc/extra/elm.kak new file mode 100644 index 00000000..aee90201 --- /dev/null +++ b/rc/extra/elm.kak @@ -0,0 +1,71 @@ +# http://elm-lang.org +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +# Detection +# ‾‾‾‾‾‾‾‾‾ + +hook global BufCreate .*[.](elm) %{ + set buffer filetype elm +} + +# Highlighters +# ‾‾‾‾‾‾‾‾‾‾‾‾ + +add-highlighter -group / regions -default code elm \ + string '"' (?<!\\)(\\\\)*" '' \ + comment (--) $ '' \ + comment \{- -\} \{- \ + +add-highlighter -group /elm/string fill string +add-highlighter -group /elm/comment fill comment + +add-highlighter -group /elm/code regex \b(import|exposing|as|module|where)\b 0:meta +add-highlighter -group /elm/code regex \b(True|False)\b 0:value +add-highlighter -group /elm/code regex \b(if|then|else|case|of|let|in|type|port|alias)\b 0:keyword +add-highlighter -group /elm/code regex \b(Array|Bool|Char|Float|Int|String)\b 0:type + +# Commands +# ‾‾‾‾‾‾‾‾ + +# http://elm-lang.org/docs/style-guide + +def -hidden elm-filter-around-selections %{ + # remove trailing white spaces + try %{ exec -draft -itersel <a-x> s \h+$ <ret> d } +} + +def -hidden elm-indent-after " + exec -draft \\; k x <a-k> ^\\h*(if)|(case\\h+[\\w']+\\h+of|let|in|\\{\\h+\\w+|\\w+\\h+->|[=(])$ <ret> j <a-gt> +" + +def -hidden elm-indent-on-new-line %{ + eval -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ exec -draft k <a-x> s ^\h*\K--\h* <ret> y gh j P } + # preserve previous line indent + try %{ exec -draft \; K <a-&> } + # align to first clause + try %{ exec -draft \; k x X s ^\h*(if|then|else)?\h*(([\w']+\h+)+=)?\h*(case\h+[\w']+\h+of|let)\h+\K.* <ret> s \`|.\' <ret> & } + # filter previous line + try %{ exec -draft k : elm-filter-around-selections <ret> } + # indent after lines beginning with condition or ending with expression or =( + try %{ elm-indent-after } + } +} + +# Initialization +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ + +hook -group elm-highlight global WinSetOption filetype=elm %{ add-highlighter ref elm } + +hook global WinSetOption filetype=elm %{ + hook window InsertEnd .* -group elm-hooks elm-filter-around-selections + hook window InsertChar \n -group elm-indent elm-indent-on-new-line +} + +hook -group elm-highlight global WinSetOption filetype=(?!elm).* %{ remove-highlighter elm } + +hook global WinSetOption filetype=(?!elm).* %{ + remove-hooks window elm-indent + remove-hooks window elm-hooks +} |
