kakoune

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

mlb.kak (1727B)


      1 # http://mlton.org/MLBasis
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # Detection
      5 # ‾‾‾‾‾‾‾‾‾
      6 
      7 hook global BufCreate .*\.mlb %{
      8     set-option buffer filetype mlb
      9 }
     10 
     11 # Initialization
     12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     13 
     14 hook global WinSetOption filetype=mlb %{
     15     require-module mlb
     16     set-option buffer extra_word_chars '_' '-' '.'
     17     set-option window static_words %opt{mlb_static_words}
     18 }
     19 
     20 hook -group mlb-highlight global WinSetOption filetype=mlb %{
     21     add-highlighter window/mlb ref mlb
     22     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/mlb }
     23 }
     24 
     25 provide-module mlb %[
     26 
     27 # Highlighters
     28 # ‾‾‾‾‾‾‾‾‾‾‾‾
     29 
     30 add-highlighter shared/mlb regions
     31 add-highlighter shared/mlb/code default-region group
     32 add-highlighter shared/mlb/string region '"' '(?<!\\)(\\\\)*"' group
     33 add-highlighter shared/mlb/string/fill fill string
     34 add-highlighter shared/mlb/comment region -recurse '\(\*' '\(\*' '\*\)' fill comment
     35 
     36 evaluate-commands %sh{
     37     keywords='basis bas and open local let in end structure signature functor ann'
     38 
     39     join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
     40 
     41     printf %s\\n "declare-option str-list mlb_static_words $(join "${keywords}" ' ')"
     42     printf %s\\n "add-highlighter shared/mlb/code/ regex (?<![\w'-/.])($(join "${keywords}" '|'))(?![\w'-/.]) 0:keyword"
     43 }
     44 add-highlighter shared/mlb/code/ regex "=" 0:operator
     45 add-highlighter shared/mlb/code/ regex "\b([A-Z][\w']*)\b" 0:type
     46 add-highlighter shared/mlb/code/ regex "\b[A-Z]{2}[A-Z0-9_']+\b" 0:attribute
     47 add-highlighter shared/mlb/code/ regex "\$\(\w+\)" 0:variable
     48 add-highlighter shared/mlb/string/ regex "\$\(\w*\)" 0:variable
     49 
     50 ]