kakoune

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

fidl.kak (3088B)


      1 # Detection
      2 hook global BufCreate .*\.fidl %{
      3     set-option buffer filetype fidl
      4 }
      5 
      6 hook global WinSetOption filetype=fidl %<
      7     require-module fidl
      8     hook window ModeChange pop:insert:.* -group fidl-trim-indent fidl-trim-indent
      9     hook window InsertChar \n -group fidl-indent fidl-indent-on-new-line
     10     hook window InsertChar [)}] -group fidl-indent fidl-indent-on-closing
     11     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window fidl-.+ }
     12 >
     13 
     14 hook -group fidl-highlight global WinSetOption filetype=fidl %{
     15     add-highlighter window/fidl ref fidl
     16     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/fidl }
     17 }
     18 
     19 provide-module fidl %§
     20 
     21 # Highlighters
     22 
     23 add-highlighter shared/fidl regions
     24 add-highlighter shared/fidl/code default-region group
     25 
     26 add-highlighter shared/fidl/string region \" (?<!\\)(\\\\)*" fill string
     27 
     28 add-highlighter shared/fidl/line_doc region ///(?!/) $ fill documentation
     29 add-highlighter shared/fidl/line_comment region // $ group
     30 add-highlighter shared/fidl/line_comment/comment fill comment
     31 add-highlighter shared/fidl/line_comment/todo regex TODO|FIXME: 0:meta
     32 
     33 add-highlighter shared/fidl/attributes region @[a-zA-Z] \b fill meta
     34 
     35 add-highlighter shared/fidl/code/keywords regex \b(as|bits|compose|const|enum|error|flexible|optional|library|protocol|resource|service|strict|struct|table|type|union|using)\b 0:keyword
     36 add-highlighter shared/fidl/code/types regex \b(array|bool|bytes?|client_end|float(32|64)|server_end|string|u?int(8|16|32|64)|vector)\b 0:type
     37 
     38 add-highlighter shared/fidl/code/literals group
     39 add-highlighter shared/fidl/code/literals/bool regex \b(true|false)\b 0:value
     40 add-highlighter shared/fidl/code/literals/decimal regex \b([0-9]+(\.[0-9]+)?)\b 0:value
     41 add-highlighter shared/fidl/code/literals/hexadecimal regex \b(0x[0-9a-fA-F])\b 0:value
     42 add-highlighter shared/fidl/code/literals/binary regex \b(0b[01])\b 0:value
     43 
     44 # Commands
     45 
     46 define-command -hidden fidl-trim-indent %{
     47     # remove trailing white spaces
     48     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     49 }
     50 
     51 define-command -hidden fidl-indent-on-new-line %~
     52     evaluate-commands -draft -itersel %@
     53         try %{ # line comment
     54             # copy the commenting prefix
     55             execute-keys -draft k x s ^\h*/{2,}\h* <ret> yjghP
     56         } catch %`
     57             # preserve previous line indent
     58             try %{ execute-keys -draft <semicolon> K <a-&> }
     59             # align to opening ( or { if possible
     60             try %+
     61                 execute-keys -draft <a-k> [)}] <ret> m <a-S> 1<a-&>
     62             + catch %+
     63                 # indent after lines ending with ( or {
     64                 try %! execute-keys -draft k x <a-k> [({]$ <ret> j <a-gt> !
     65             +
     66         `
     67         # remove trailing white spaces
     68         try %{ execute-keys -draft k : fidl-trim-indent <ret> }
     69     @
     70 ~
     71 
     72 define-command -hidden fidl-indent-on-closing %~
     73     evaluate-commands -draft -itersel %@
     74         # align to opening ( or { when alone on a line
     75         try %< execute-keys -draft <a-h> <a-k> ^\h*[)}]$ <ret> m <a-S> 1<a-&> >
     76     @
     77 ~
     78 
     79 §