kakoune/rc/extra/cucumber.kak

93 lines
2.9 KiB
Plaintext
Raw Normal View History

2014-07-15 23:32:17 +02:00
# http://cukes.info
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufCreate .*[.](feature|story) %{
set buffer filetype cucumber
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
2017-01-04 01:07:45 +01:00
add-highlighter -group / regions -default code cucumber \
2014-07-15 23:32:17 +02:00
language ^\h*#\h*language: $ '' \
comment ^\h*# $ ''
2017-01-04 01:07:45 +01:00
add-highlighter -group /cucumber/language fill meta
add-highlighter -group /cucumber/comment fill comment
2014-07-15 23:32:17 +02:00
2017-01-04 01:07:45 +01:00
add-highlighter -group /cucumber/language regex \S+$ 0:value
2014-07-15 23:32:17 +02:00
# Spoken languages
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# https://github.com/cucumber/cucumber/wiki/Spoken-languages
#
# curl --location https://github.com/cucumber/gherkin/raw/master/lib/gherkin/i18n.json
#
# {
# "en": {
# "name": "English",
# "native": "English",
# "feature": "Feature|Business Need|Ability",
# "background": "Background",
# "scenario": "Scenario",
# "scenario_outline": "Scenario Outline|Scenario Template",
# "examples": "Examples|Scenarios",
# "given": "*|Given",
# "when": "*|When",
# "then": "*|Then",
# "and": "*|And",
# "but": "*|But"
# },
# …
# }
#
# jq 'with_entries({ key: .key, value: .value | del(.name) | del(.native) | join("|") })'
#
# {
# "en": "Feature|Business Need|Ability|Background|Scenario|Scenario Outline|Scenario Template|Examples|Scenarios|*|Given|*|When|*|Then|*|And|*|But",
# …
# }
2017-01-04 01:07:45 +01:00
add-highlighter -group /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
2014-07-15 23:32:17 +02:00
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _cucumber_filter_around_selections %{
# remove trailing white spaces
try %{ exec -draft -itersel <a-x> s \h+$ <ret> d }
2014-07-15 23:32:17 +02:00
}
def -hidden _cucumber_indent_on_new_line %{
eval -draft -itersel %{
# copy '#' comment prefix and following white spaces
try %{ exec -draft k <a-x> s ^\h*\K#\h* <ret> y gh j P }
2014-07-15 23:32:17 +02:00
# preserve previous line indent
try %{ exec -draft \; K <a-&> }
2014-07-15 23:32:17 +02:00
# filter previous line
try %{ exec -draft k : _cucumber_filter_around_selections <ret> }
# indent after lines containing :
try %{ exec -draft <space> k x <a-k> : <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
2017-01-04 01:07:45 +01:00
hook -group cucumber-highlight global WinSetOption filetype=cucumber %{ add-highlighter ref cucumber }
2014-07-15 23:32:17 +02:00
hook global WinSetOption filetype=cucumber %{
2014-07-15 23:32:17 +02:00
hook window InsertEnd .* -group cucumber-hooks _cucumber_filter_around_selections
hook window InsertChar \n -group cucumber-indent _cucumber_indent_on_new_line
}
2017-01-04 01:07:45 +01:00
hook -group cucumber-highlight global WinSetOption filetype=(?!cucumber).* %{ remove-highlighter cucumber }
2014-07-15 23:32:17 +02:00
hook global WinSetOption filetype=(?!cucumber).* %{
2017-01-04 01:07:45 +01:00
remove-hooks window cucumber-indent
remove-hooks window cucumber-hooks
2014-07-15 23:32:17 +02:00
}