kakoune

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

snakefile.kak (2851B)


      1 # https://snakemake.github.io
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 # SnakeMake is a pipeline/workflow management system.
      4 
      5 # Detection
      6 # ‾‾‾‾‾‾‾‾‾
      7 
      8 hook global BufCreate .*\.([Ss]nake[Ff]ile) %{
      9     set-option buffer filetype snakefile
     10 }
     11 
     12 # Initialization
     13 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     14 
     15 hook global WinSetOption filetype=snakefile %{
     16     require-module snakefile
     17 
     18     hook window ModeChange pop:insert:.* -group snakefile-trim-indent snakefile-trim-indent
     19     hook window InsertChar \n -group snakefile-insert snakefile-insert-on-new-line
     20     hook window InsertChar \n -group snakefile-indent snakefile-indent-on-new-line
     21     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window snakefile-.+ }
     22 }
     23 
     24 hook -group snakefile-highlight global WinSetOption filetype=snakefile %{
     25     add-highlighter window/snakefile ref snakefile
     26     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/snakefile }
     27 }
     28 
     29 
     30 provide-module snakefile %{
     31 
     32 require-module python
     33 
     34 # Highlighters
     35 # ‾‾‾‾‾‾‾‾‾‾‾‾
     36 
     37 add-highlighter shared/snakefile regions
     38 add-highlighter shared/snakefile/comment  region '(?:^| )#' $   fill comment
     39 
     40 add-highlighter shared/snakefile/code  default-region group
     41 add-highlighter shared/snakefile/code/ regex \bconfig\b    0:builtin
     42 add-highlighter shared/snakefile/code/ regex \bwildcards\b 0:builtin
     43 add-highlighter shared/snakefile/code/ regex ^(\w+): 1:attribute
     44 add-highlighter shared/snakefile/code/ regex ^(rule)\s+(\w+): 1:keyword 2:module
     45 add-highlighter shared/snakefile/code/ regex ^\s{4}(\w+):   1:attribute
     46 
     47 add-highlighter shared/snakefile/section  region ^\s{8} \n  group
     48 add-highlighter shared/snakefile/section/ ref python
     49 add-highlighter shared/snakefile/section/f_string regex \{.*?\} 0:value
     50 add-highlighter shared/snakefile/section/keywords regex \bconfig\b    0:builtin  # FIXME
     51 add-highlighter shared/snakefile/section/keywords regex \bwildcards\b 0:builtin  # FIXME
     52 
     53 # Commands
     54 # ‾‾‾‾‾‾‾‾
     55 
     56 define-command -hidden snakefile-trim-indent %{
     57     # remove trailing white spaces
     58     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     59 }
     60 
     61 define-command -hidden snakefile-insert-on-new-line %{
     62     evaluate-commands -draft -itersel %{
     63         # copy '#' comment prefix and following white spaces
     64         try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
     65     }
     66 }
     67 
     68 define-command -hidden snakefile-indent-on-new-line %{
     69     evaluate-commands -draft -itersel %{
     70         # preserve previous line indent
     71         try %{ execute-keys -draft <semicolon> K <a-&> }
     72         # filter previous line
     73         try %{ execute-keys -draft k : snakefile-trim-indent <ret> }
     74         # indent after :
     75         try %{ execute-keys -draft , k x <a-k> :$ <ret> j <a-gt> }
     76     }
     77 }
     78 
     79 }
     80