kakoune

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

ragel.kak (3475B)


      1 # http://complang.org/ragel
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # ragel.kak does not try to detect host language.
      5 
      6 # Detection
      7 # ‾‾‾‾‾‾‾‾‾
      8 
      9 hook global BufCreate .*[.](ragel|rl) %{
     10     set-option buffer filetype ragel
     11 }
     12 
     13 # Initialization
     14 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     15 
     16 hook global WinSetOption filetype=ragel %{
     17     require-module ragel
     18 
     19     hook window ModeChange pop:insert:.* -group ragel-trim-indent ragel-trim-indent
     20     hook window InsertChar .* -group ragel-indent ragel-indent-on-char
     21     hook window InsertChar \n -group ragel-insert ragel-insert-on-new-line
     22     hook window InsertChar \n -group ragel-indent ragel-indent-on-new-line
     23 
     24     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window ragel-.+ }
     25 }
     26 
     27 hook -group ragel-highlight global WinSetOption filetype=ragel %{
     28     add-highlighter window/ragel ref ragel
     29     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/ragel }
     30 }
     31 
     32 provide-module ragel %§
     33 
     34 # Highlighters
     35 # ‾‾‾‾‾‾‾‾‾‾‾‾
     36 
     37 add-highlighter shared/ragel regions
     38 add-highlighter shared/ragel/code default-region group
     39 add-highlighter shared/ragel/double_string region '"' (?<!\\)(\\\\)*"         fill string
     40 add-highlighter shared/ragel/single_string region "'" "'"                     fill string
     41 add-highlighter shared/ragel/comment region '#' '$'                     fill comment
     42 
     43 add-highlighter shared/ragel/code/ regex \b(true|false)\b 0:value
     44 add-highlighter shared/ragel/code/ regex '%%\{|\}%%|<\w+>' 0:variable
     45 add-highlighter shared/ragel/code/ regex :=|=>|->|:>|:>>|<: 0:operator
     46 add-highlighter shared/ragel/code/ regex \b(action|alnum|alpha|any|ascii|case|cntrl|contained|context|data|digit|empty|eof|err|error|exec|export|exports|extend|fblen|fbreak|fbuf|fc|fcall|fcurs|fentry|fexec|fgoto|fhold|first_final|fnext|fpc|fret|from|fstack|ftargs|graph|import|include|init|inwhen|lerr|lower|machine|nocs|noend|noerror|nofinal|noprefix|outwhen|postpop|prepush|print|punct|range|space|start|to|upper|when|write|xdigit|zlen)\b 0:keyword
     47 
     48 # Commands
     49 # ‾‾‾‾‾‾‾‾
     50 
     51 define-command -hidden ragel-trim-indent %{
     52     # remove trailing white spaces
     53     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     54 }
     55 
     56 define-command -hidden ragel-indent-on-char %<
     57     evaluate-commands -draft -itersel %<
     58         # align closer token to its opener when alone on a line
     59         try %< execute-keys -draft <a-h> <a-k> ^\h+[\]})]$ <ret>        m         s \A|.\z <ret> 1<a-&> >
     60         try %< execute-keys -draft <a-h> <a-k> ^\h+   [*]$ <ret> <a-?> [*]$ <ret> s \A|.\z <ret> 1<a-&> >
     61     >
     62 >
     63 
     64 define-command -hidden ragel-insert-on-new-line %<
     65     evaluate-commands -draft -itersel %<
     66         # copy _#_ comment prefix and following white spaces
     67         try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
     68     >
     69 >
     70 
     71 define-command -hidden ragel-indent-on-new-line %<
     72     evaluate-commands -draft -itersel %<
     73         # preserve previous line indent
     74         try %{ execute-keys -draft <semicolon> K <a-&> }
     75         # filter previous line
     76         try %{ execute-keys -draft k : ragel-trim-indent <ret> }
     77         # indent after lines ending with opener token
     78         try %< execute-keys -draft k x <a-k> [[{(*]$ <ret> j <a-gt> >
     79         # align closer token to its opener when after cursor
     80         try %< execute-keys -draft x <a-k> ^\h*[})\]] <ret> gh / [})\]] <ret> m <a-S> 1<a-&> >
     81     >
     82 >
     83 
     84 §