kakoune

Fork of kakoune, an acceptable text editor
git clone git://git.laack.co/kakoune.git
Log | Files | Refs

elm.kak (3549B)


      1 # http://elm-lang.org
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # Detection
      5 # ‾‾‾‾‾‾‾‾‾
      6 
      7 hook global BufCreate .*[.](elm) %{
      8     set-option buffer filetype elm
      9 }
     10 
     11 # Initialization
     12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     13 
     14 hook global WinSetOption filetype=elm %{
     15     require-module elm
     16 
     17     hook window ModeChange pop:insert:.* -group elm-trim-indent elm-trim-indent
     18     hook window InsertChar \n -group elm-insert elm-insert-on-new-line
     19     hook window InsertChar \n -group elm-indent elm-indent-on-new-line
     20 
     21     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window elm-.+ }
     22 }
     23 
     24 hook -group elm-highlight global WinSetOption filetype=elm %{
     25     add-highlighter window/elm ref elm
     26     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/elm }
     27 }
     28 
     29 
     30 provide-module elm %[
     31 
     32 # Highlighters
     33 # ‾‾‾‾‾‾‾‾‾‾‾‾
     34 
     35 add-highlighter shared/elm               regions
     36 add-highlighter shared/elm/code          default-region group
     37 add-highlighter shared/elm/multiline_string region '"""' '"""' fill string
     38 add-highlighter shared/elm/string        region         '"'     (?<!\\)(\\\\)*"       fill string
     39 add-highlighter shared/elm/line_comment  region         (--) $                        fill comment
     40 add-highlighter shared/elm/comment       region         -recurse \{- \{-   -\}        fill comment
     41 
     42 add-highlighter shared/elm/code/ regex \b[A-Z]\w*\b                                                        0:type
     43 add-highlighter shared/elm/code/ regex \b[a-z]\w*\b                                                        0:variable
     44 add-highlighter shared/elm/code/ regex ^[a-z]\w*\b                                                         0:function
     45 add-highlighter shared/elm/code/ regex "-?\b[0-9]*\.?[0-9]+"                                               0:value
     46 add-highlighter shared/elm/code/ regex \B[-+<>!@#$%^&*=:/\\|]+\B                                           0:operator
     47 add-highlighter shared/elm/code/ regex \b(import|exposing|as|module|port)\b                                0:meta
     48 add-highlighter shared/elm/code/ regex \b(type|alias|if|then|else|case|of|let|in|infix|_)\b)               0:keyword
     49 add-highlighter shared/elm/code/ regex (?<![-+<>!@#$%^&*=:/\\|])(->|:|=|\|)(?![-+<>!@#$%^&*=:/\\|])        0:keyword
     50 
     51 # Commands
     52 # ‾‾‾‾‾‾‾‾
     53 
     54 # http://elm-lang.org/docs/style-guide
     55 
     56 define-command -hidden elm-trim-indent %{
     57     # remove trailing white spaces
     58     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     59 }
     60 
     61 define-command -hidden elm-indent-after "
     62  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>
     63 "
     64 
     65 define-command -hidden elm-insert-on-new-line %{
     66     evaluate-commands -draft -itersel %{
     67         # copy -- comments prefix and following white spaces
     68         try %{ execute-keys -draft k x s ^\h*\K--\h* <ret> y gh j P }
     69     }
     70 }
     71 
     72 define-command -hidden elm-indent-on-new-line %{
     73     evaluate-commands -draft -itersel %{
     74         # preserve previous line indent
     75         try %{ execute-keys -draft <semicolon> K <a-&> }
     76         # align to first clause
     77         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> & }
     78         # filter previous line
     79         try %{ execute-keys -draft k : elm-trim-indent <ret> }
     80         # indent after lines beginning with condition or ending with expression or =(
     81         try %{ elm-indent-after }
     82     }
     83 }
     84 
     85 ]