gherkin.kak (2884B)
1 # https://github.com/cucumber/gherkin 2 # https://cucumber.io/docs/gherkin/reference 3 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 4 # 5 # Detection 6 # ‾‾‾‾‾‾‾‾‾ 7 hook global BufCreate '.*\.feature$' %{ 8 set-option buffer filetype gherkin 9 } 10 11 # Initialization 12 # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ 13 hook global WinSetOption filetype=gherkin %{ 14 require-module gherkin 15 16 evaluate-commands set-option window static_words %opt{gherkin_static_words} 17 18 # cleanup trailing whitespaces when exiting insert mode 19 hook window ModeChange pop:insert:.* -group gherkin-trim-indent %{ try %{ execute-keys -draft xs^\h+$<ret>d } } 20 hook window InsertChar \n -group gherkin-insert gherkin-insert-on-new-line 21 hook window InsertChar \n -group gherkin-indent gherkin-indent-on-new-line 22 23 hook -once -always window WinSetOption filetype=.* %{ remove-hooks window gherkin-.+ } 24 } 25 26 hook -group gherkin-highlight global WinSetOption filetype=gherkin %{ 27 add-highlighter window/gherkin ref gherkin 28 hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/gherkin } 29 } 30 31 provide-module gherkin %§ 32 33 # Highlighters 34 # ‾‾‾‾‾‾‾‾‾‾‾‾ 35 add-highlighter shared/gherkin regions 36 add-highlighter shared/gherkin/code default-region group 37 # Double quoted strings 38 add-highlighter shared/gherkin/double_quote region %{(?<!')"} %{(?<!\\)(\\\\)*"} fill string 39 # Triple quoted strings 40 add-highlighter shared/gherkin/triple_quote region %{(?<!')"""} %{(?<!\\)(\\\\)*"""} fill string 41 # Comments - single line 42 add-highlighter shared/gherkin/comment_line region %{#} %{$} fill comment 43 # Tags 44 add-highlighter shared/gherkin/code/ regex %{\h*(@[\w\d]+(-[\w\d]+)?)\b} 1:meta 45 # Data table 46 add-highlighter shared/gherkin/code/ regex %{(?S)^\h*(\|.*\|)$} 1:value 47 # Keywords 48 add-highlighter shared/gherkin/code/ regex %{\b(Feature|Rule|Examples?|Scenarios?|Outline|Template|Given|When|Then|And|But|\*|Background)\b} 1:keyword 49 50 # Completers 51 # ‾‾‾‾‾‾‾‾‾‾ 52 declare-option -hidden str-list gherkin_static_words 'Feature' 'Rule' 'Example' 'Examples' 'Scenario' 'Outline' 'Template' 'Scenarios' 'Given' 'When' 'Then' 'And' 'But' '*' 'Background' 53 54 # Commands 55 # ‾‾‾‾‾‾‾‾ 56 define-command -hidden gherkin-insert-on-new-line %[ 57 evaluate-commands -draft -itersel %[ 58 # copy # comments prefix and following white spaces 59 try %{ execute-keys -draft <semicolon><c-s>kx s ^\h*\K#\h* <ret> y<c-o>P<esc> } 60 ] 61 ] 62 63 define-command -hidden gherkin-indent-on-new-line %[ 64 evaluate-commands -draft -itersel %[ 65 # preserve previous line indent 66 try %{ execute-keys -draft <semicolon>K<a-&> } 67 # cleanup trailing white spaces on the previous line 68 try %{ execute-keys -draft kx s \h+$ <ret>d } 69 ] 70 ] 71 §