kakoune

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

gluon.kak (3506B)


      1 # http://gluon-lang.org
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # Detection
      5 # ‾‾‾‾‾‾‾‾‾
      6 
      7 hook global BufCreate .*[.](glu) %{
      8     set-option buffer filetype gluon
      9 }
     10 
     11 # Initialization
     12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     13 
     14 hook global WinSetOption filetype=gluon %{
     15     require-module gluon
     16 
     17     set-option window extra_word_chars '_' "'"
     18     hook window ModeChange pop:insert:.* -group gluon-trim-indent gluon-trim-indent
     19     hook window InsertChar \n -group gluon-insert gluon-insert-on-new-line
     20     hook window InsertChar \n -group gluon-indent gluon-indent-on-new-line
     21 
     22     hook -once -always window WinSetOption filetype=.* %{
     23         remove-hooks window gluon-.+
     24     }
     25 }
     26 
     27 hook -group gluon-highlight global WinSetOption filetype=gluon %{
     28     add-highlighter window/gluon ref gluon
     29     hook -once -always window WinSetOption filetype=.* %{
     30         remove-highlighter window/gluon
     31     }
     32 }
     33 
     34 
     35 provide-module gluon %§
     36 
     37 # Highlighters
     38 # ‾‾‾‾‾‾‾‾‾‾‾‾
     39 
     40 add-highlighter shared/gluon regions
     41 add-highlighter shared/gluon/code default-region group
     42 add-highlighter shared/gluon/string region (?<!')" (?<!\\)(\\\\)*" fill string
     43 add-highlighter shared/gluon/raw_string region -match-capture \br(#+)" \"(#+) fill string
     44 add-highlighter shared/gluon/comment region /\* \*/ fill comment
     45 add-highlighter shared/gluon/line_comment region // $ fill comment
     46 add-highlighter shared/gluon/attribute region -recurse \[ '#\[' \] fill meta
     47 # balance out bracket ]
     48 
     49 # matches hexadecimal literals
     50 add-highlighter shared/gluon/code/ regex \b0x+[A-Fa-f0-9]+ 0:value
     51 # matches decimal and floating-point literals
     52 add-highlighter shared/gluon/code/ regex \b\d+([.]\d+)? 0:value
     53 
     54 # matches keywords
     55 add-highlighter shared/gluon/code/ regex \
     56     (?<!')\b(type|if|then|else|match|with|let|rec|do|seq|in)\b(?!') 0:keyword
     57 
     58 # matches macros
     59 add-highlighter shared/gluon/code/ regex \b\w+! 0:meta
     60 
     61 # matches uppercase identifiers: Monad Some
     62 add-highlighter shared/gluon/code/ regex \b[A-Z][\w']* 0:variable
     63 
     64 # matches operators: ... > < <= ^ <*> <$> etc
     65 # matches dot: .
     66 # matches keywords:  @ : ->
     67 add-highlighter shared/gluon/code/ regex (?<![~<=>|:!?/.@$*&#%+\^\-\\])[~<=>|:!?/.@$*&#%+\^\-\\]+ 0:operator
     68 
     69 # matches 'x' '\\' '\'' '\n' '\0'
     70 # not incomplete literals: '\'
     71 add-highlighter shared/gluon/code/ regex \B'([^\\]|[\\]['"\w\d\\])' 0:string
     72 # this has to come after operators so '-' etc is correct
     73 
     74 # Commands
     75 # ‾‾‾‾‾‾‾‾
     76 
     77 define-command -hidden gluon-trim-indent %{
     78     # remove trailing white spaces
     79     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     80 }
     81 
     82 define-command -hidden gluon-insert-on-new-line %~
     83     evaluate-commands -draft -itersel %_
     84         # copy // and /// comments prefix and following white spaces
     85         try %{ execute-keys -draft k x s ^\h*\K///?\h* <ret> y gh j P }
     86     _
     87 ~
     88 
     89 define-command -hidden gluon-indent-on-new-line %~
     90     evaluate-commands -draft -itersel %_
     91         # preserve previous line indent
     92         try %{ execute-keys -draft \; K <a-&> }
     93         # filter previous line
     94         try %{ execute-keys -draft k : gluon-trim-indent <ret> }
     95         # indent after lines ending with (open) braces, =, ->, condition, rec,
     96         # or in
     97         try %, execute-keys -draft \; k x <a-k> (\(|\{|\[|=|->|\b(?:then|else|rec|in))$ <ret> j <a-gt> ,
     98         # deindent closing brace(s) when after cursor
     99         try %< execute-keys -draft x <a-k> ^\h*[})\]] <ret> gh / \})\]] <ret> m <a-S> 1<a-&> >
    100     _
    101 ~
    102 
    103 §