kakoune

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

cucumber.kak (3292B)


      1 # http://cukes.info
      2 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
      3 
      4 # Detection
      5 # ‾‾‾‾‾‾‾‾‾
      6 
      7 hook global BufCreate .*[.](feature|story) %{
      8     set-option buffer filetype cucumber
      9 }
     10 
     11 # Initialization
     12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     13 
     14 hook global WinSetOption filetype=cucumber %{
     15     require-module cucumber
     16 
     17     hook window ModeChange pop:insert:.* -group cucumber-trim-indent cucumber-trim-indent
     18     hook window InsertChar \n -group cucumber-insert cucumber-insert-on-new-line
     19     hook window InsertChar \n -group cucumber-indent cucumber-indent-on-new-line
     20 
     21     hook -once -always window WinSetOption filetype=.* %{ remove-hooks window cucumber-.+ }
     22 }
     23 
     24 hook -group cucumber-highlight global WinSetOption filetype=cucumber %{
     25     add-highlighter window/cucumber ref cucumber
     26     hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/cucumber }
     27 }
     28 
     29 
     30 provide-module cucumber %{
     31 
     32 # Highlighters
     33 # ‾‾‾‾‾‾‾‾‾‾‾‾
     34 
     35 add-highlighter shared/cucumber regions
     36 add-highlighter shared/cucumber/code default-region group
     37 add-highlighter shared/cucumber/language region ^\h*#\h*language: $ group
     38 add-highlighter shared/cucumber/comment  region ^\h*#             $ fill comment
     39 
     40 add-highlighter shared/cucumber/language/ fill meta
     41 add-highlighter shared/cucumber/language/ regex \S+$ 0:value
     42 
     43 # Spoken languages
     44 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
     45 # https://github.com/cucumber/cucumber/wiki/Spoken-languages
     46 #
     47 # curl --location https://github.com/cucumber/gherkin/raw/master/lib/gherkin/i18n.json
     48 #
     49 # {
     50 #   "en": {
     51 #     "name": "English",
     52 #     "native": "English",
     53 #     "feature": "Feature|Business Need|Ability",
     54 #     "background": "Background",
     55 #     "scenario": "Scenario",
     56 #     "scenario_outline": "Scenario Outline|Scenario Template",
     57 #     "examples": "Examples|Scenarios",
     58 #     "given": "*|Given",
     59 #     "when": "*|When",
     60 #     "then": "*|Then",
     61 #     "and": "*|And",
     62 #     "but": "*|But"
     63 #   },
     64 #   …
     65 # }
     66 #
     67 # jq 'with_entries({ key: .key, value: .value | del(.name) | del(.native) | join("|") })'
     68 #
     69 # {
     70 #   "en": "Feature|Business Need|Ability|Background|Scenario|Scenario Outline|Scenario Template|Examples|Scenarios|*|Given|*|When|*|Then|*|And|*|But",
     71 #   …
     72 # }
     73 
     74 add-highlighter shared/cucumber/code/ regex \b(Feature|Business\h+Need|Ability|Background|Scenario|Scenario\h+Outline|Scenario\h+Template|Examples|Scenarios|Given|When|Then|And|But)\b 0:keyword
     75 
     76 # Commands
     77 # ‾‾‾‾‾‾‾‾
     78 
     79 define-command -hidden cucumber-trim-indent %{
     80     # remove trailing white spaces
     81     try %{ execute-keys -draft -itersel x s \h+$ <ret> d }
     82 }
     83 
     84 define-command -hidden cucumber-insert-on-new-line %{
     85     evaluate-commands -draft -itersel %{
     86         # copy '#' comment prefix and following white spaces
     87         try %{ execute-keys -draft k x s ^\h*\K#\h* <ret> y gh j P }
     88     }
     89 }
     90 
     91 define-command -hidden cucumber-indent-on-new-line %{
     92     evaluate-commands -draft -itersel %{
     93         # preserve previous line indent
     94         try %{ execute-keys -draft <semicolon> K <a-&> }
     95         # filter previous line
     96         try %{ execute-keys -draft k : cucumber-trim-indent <ret> }
     97         # indent after lines containing :
     98         try %{ execute-keys -draft , k x <a-k> : <ret> j <a-gt> }
     99     }
    100 }
    101 
    102 }