From ec77784d98d0966521f917557fe129e4d22ec958 Mon Sep 17 00:00:00 2001 From: Tom Miller Date: Sun, 12 Feb 2017 16:25:53 -0600 Subject: [PATCH 2/2] Add elm language support Using Haskell's language file as a starting point this add support for Elm. --- rc/extra/elm.kak | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 rc/extra/elm.kak 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 '"' (? s \h+$ d } +} + +def -hidden elm-indent-after " + exec -draft \\; k x ^\\h*(if)|(case\\h+[\\w']+\\h+of|let|in|\\{\\h+\\w+|\\w+\\h+->|[=(])$ j +" + +def -hidden elm-indent-on-new-line %{ + eval -draft -itersel %{ + # copy -- comments prefix and following white spaces + try %{ exec -draft k s ^\h*\K--\h* y gh j P } + # preserve previous line indent + try %{ exec -draft \; K } + # 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.* s \`|.\' & } + # filter previous line + try %{ exec -draft k : elm-filter-around-selections } + # 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 +}