Merge some more language support from alexherbo2

* alexherbo2/haml-rc
 * alexherbo2/cucumber-rc
 * alexherbo2/sass-rc
 * alexherbo2/scss-rc
 * alexherbo2/ragel-rc
 * alexherbo2/coffee-rc
 * alexherbo2/rust-rc
This commit is contained in:
Maxime Coste 2014-07-30 20:46:25 +01:00
7 changed files with 556 additions and 0 deletions

87
rc/coffee.kak Normal file
View File

@ -0,0 +1,87 @@
# http://coffeescript.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-coffee %{
set buffer filetype coffee
}
hook global BufCreate .*[.](coffee) %{
set buffer filetype coffee
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / regions -default code coffee \
double_string '"""' '"""' '' \
single_string "'''" "'''" '' \
comment '###' '###' '' \
regex '///' ///[gimy]* '' \
double_string '"' (?<!\\)(\\\\)*" '' \
single_string "'" "'" '' \
regex '/' (?<!\\)(\\\\)*/[gimy]* '' \
comment '#' '$' ''
# Regular expression flags are: g → global match, i → ignore case, m → multi-lines, y → sticky
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
addhl -group /coffee/double_string fill string
addhl -group /coffee/double_string regions regions interpolation \Q#{ \} \{
addhl -group /coffee/double_string/regions/interpolation fill meta
addhl -group /coffee/single_string fill string
addhl -group /coffee/regex fill meta
addhl -group /coffee/regex regions regions interpolation \Q#{ \} \{
addhl -group /coffee/regex/regions/interpolation fill meta
addhl -group /coffee/comment fill comment
# Keywords are collected at
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
# http://coffeescript.org/documentation/docs/lexer.html#section-63
addhl -group /coffee/code regex [$@]\w* 0:identifier
addhl -group /coffee/code regex \<(Array|Boolean|Date|Function|Number|Object|RegExp|String)\> 0:type
addhl -group /coffee/code regex \<(document|false|no|null|off|on|parent|self|this|true|undefined|window|yes)\> 0:value
addhl -group /coffee/code regex \<(and|is|isnt|not|or)\> 0:operator
addhl -group /coffee/code regex \<(break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|function|if|implements|import|in|instanceof|interface|let|native|new|package|private|protected|public|return|static|super|switch|throw|try|typeof|var|void|while|with|yield)\> 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _coffee_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _coffee_indent_on_new_line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _coffee_filter_around_selections <ret> }
# copy '#' comment prefix and following white spaces
try %{ exec -draft k x s ^\h*\K#\h* <ret> y j p }
# indent after lines beginning with token and ending with ->
try %_ exec -draft k x <a-k> ^\h*(case|catch|class|else|finally|for|function|if|switch|try|while|with)|(->)$ <ret> j <a-gt> _
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=coffee %{
addhl ref coffee
hook window InsertEnd .* -group coffee-hooks _coffee_filter_around_selections
hook window InsertChar \n -group coffee-indent _coffee_indent_on_new_line
}
hook global WinSetOption filetype=(?!coffee).* %{
rmhl coffee
rmhooks window coffee-indent
rmhooks window coffee-hooks
}

98
rc/cucumber.kak Normal file
View File

@ -0,0 +1,98 @@
# http://cukes.info
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-cucumber %{
set buffer filetype cucumber
}
hook global BufCreate .*[.](feature|story) %{
set buffer filetype cucumber
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / regions -default code cucumber \
language ^\h*#\h*language: $ '' \
comment ^\h*# $ ''
addhl -group /cucumber/language fill meta
addhl -group /cucumber/comment fill comment
addhl -group /cucumber/language regex \S+$ 0:value
# 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",
# …
# }
addhl -group /cucumber/code regex \<(Feature|Business\h+Need|Ability|Background|Scenario|Scenario\h+Outline|Scenario\h+Template|Examples|Scenarios|Given|When|Then|And|But)\> 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _cucumber_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _cucumber_indent_on_new_line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _cucumber_filter_around_selections <ret> }
# copy '#' comment prefix and following white spaces
try %{ exec -draft k x s ^\h*\K#\h* <ret> y j p }
# indent after lines containing :
try %{ exec -draft <space> k x <a-k> : <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=cucumber %{
addhl ref cucumber
hook window InsertEnd .* -group cucumber-hooks _cucumber_filter_around_selections
hook window InsertChar \n -group cucumber-indent _cucumber_indent_on_new_line
}
hook global WinSetOption filetype=(?!cucumber).* %{
rmhl cucumber
rmhooks window cucumber-indent
rmhooks window cucumber-hooks
}

75
rc/haml.kak Normal file
View File

@ -0,0 +1,75 @@
# http://haml.info
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-haml %{
set buffer filetype haml
}
hook global BufCreate .*[.](haml) %{
set buffer filetype haml
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / regions -default code haml \
comment ^\h*/ $ '' \
eval ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)?\{\K|#\{\K (?=\}) \{ \
eval ^\h*[=-]\K (?=[^|]\n) '' \
coffee ^\h*:coffee\K (?=^\h*[%=-]) '' \
sass ^\h*:sass\K (?=^\h*[%=-]) ''
# Filters
# http://haml.info/docs/yardoc/file.REFERENCE.html#filters
addhl -group /haml/comment fill comment
addhl -group /haml/eval ref ruby
addhl -group /haml/coffee ref coffee
addhl -group /haml/sass ref sass
addhl -group /haml/code regex ^\h*(:[a-z]+|-|=)|^(!!!)$ 0:meta
addhl -group /haml/code regex ^\h*%([A-Za-z][A-Za-z0-9_-]*)([#.][A-Za-z][A-Za-z0-9_-]*)? 1:keyword 2:identifier
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _haml_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _haml_indent_on_new_line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _haml_filter_around_selections <ret> }
# copy '/' comment prefix and following white spaces
try %{ exec -draft k x s ^\h*\K/\h* <ret> y j p }
# indent after lines beginning with : or -
try %{ exec -draft k x <a-k> ^\h*[:-] <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=haml %{
addhl ref haml
hook window InsertEnd .* -group haml-hooks _haml_filter_around_selections
hook window InsertChar \n -group haml-indent _haml_indent_on_new_line
}
hook global WinSetOption filetype=(?!haml).* %{
rmhl haml
rmhooks window haml-indent
rmhooks window haml-hooks
}

80
rc/ragel.kak Normal file
View File

@ -0,0 +1,80 @@
# http://complang.org/ragel
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# ragel.kak does not try to detect host language.
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-ragel %{
set buffer filetype ragel
}
hook global BufCreate .*[.](ragel|rl) %{
set buffer filetype ragel
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / regions -default code ragel \
string '"' (?<!\\)(\\\\)*" '' \
string "'" "'" '' \
comment '#' '$' ''
addhl -group /ragel/string fill string
addhl -group /ragel/comment fill comment
addhl -group /ragel/code regex \<(true|false)\> 0:value
addhl -group /ragel/code regex %%\{|\}%%|<\w+> 0:identifier
addhl -group /ragel/code regex :=|=>|->|:>|:>>|<: 0:operator
addhl -group /ragel/code regex \<(action|alnum|alpha|any|ascii|case|cntrl|contained|context|data|digit|empty|eof|err|error|exec|export|exports|extend|fblen|fbreak|fbuf|fc|fcall|fcurs|fentry|fexec|fgoto|fhold|first_final|fnext|fpc|fret|from|fstack|ftargs|graph|import|include|init|inwhen|lerr|lower|machine|nocs|noend|noerror|nofinal|noprefix|outwhen|postpop|prepush|print|punct|range|space|start|to|upper|when|write|xdigit|zlen)\> 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _ragel_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _ragel_indent_on_char "
eval -draft -itersel %_
# align closer token to its opener when alone on a line
try %/ exec -draft <a-h> <a-k> ^\h+[]})]$ <ret> m s \`|.\' <ret> 1<a-&> /
try %/ exec -draft <a-h> <a-k> ^\h+ [*]$ <ret> <a-?> [*]$ <ret> s \`|.\' <ret> 1<a-&> /
_
"
def -hidden _ragel_indent_on_new_line "
eval -draft -itersel '
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _ragel_filter_around_selections <ret> }
# copy _#_ comment prefix and following white spaces
try %{ exec -draft k x s ^\h*\K#\h* <ret> y j p }
# indent after lines ending with opener token
try %_ exec -draft k x <a-k> [[{(*]$ <ret> j <a-gt> _
'
"
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=ragel %{
addhl ref ragel
hook window InsertEnd .* -group ragel-hooks _ragel_filter_around_selections
hook window InsertChar .* -group ragel-indent _ragel_indent_on_char
hook window InsertChar \n -group ragel-indent _ragel_indent_on_new_line
}
hook global WinSetOption filetype=(?!ragel).* %{
rmhl ragel
rmhooks window ragel-indent
rmhooks window ragel-hooks
}

97
rc/rust.kak Normal file
View File

@ -0,0 +1,97 @@
# http://rust-lang.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-rust %{
set buffer filetype rust
}
hook global BufCreate .*[.](rust|rs) %{
set buffer filetype rust
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / regions -default code rust \
string '"' (?<!\\)(\\\\)*" '' \
comment // $ '' \
comment /\* \*/ /\* \
macro ^\h*?\K# (?<!\\)\n ''
addhl -group /rust/string fill string
addhl -group /rust/comment fill comment
addhl -group /rust/macro fill meta
addhl -group /rust/code regex \<(self|true|false)\> 0:value
addhl -group /rust/code regex \<(&&|\|\|)\> 0:operator
addhl -group /rust/code regex \<((match|if|else)|(as)|(assert)|(fail)|(yield)|(break|box|continue)|(extern)|(for|in|if|impl|let)|(loop|once|priv|pub)|(return)|(unsafe|while)|(use)|(fn)|(proc))\> 0:keyword
addhl -group /rust/code regex \<((mod|trait|struct|enum|type)|(mut|ref|static)|(const)|(alignof|be|do|offsetof|pure|sizeof|typeof))\> 0:attribute
addhl -group /rust/code regex \<((int|uint|float|char|bool|u8|u16|u32|u64|f32)|(f64|i8|i16|i32|i64|str))\> 0:type
addhl -group /rust/code regex \<(((Share|Copy|Send|Sized)|(Add|Sub|Mul|Div|Rem|Neg|Not)|(BitAnd|BitOr|BitXor)|(Drop)|(Shl|Shr|Index)|(Option)|(Some|None)|(Result)|(Ok|Err))|((Any|AnyOwnExt|AnyRefExt|AnyMutRefExt)|(Ascii|AsciiCast|OwnedAsciiCast|AsciiStr|IntoBytes)|(ToCStr)|(Char)|(Clone)|(Eq|Ord|TotalEq|TotalOrd|Ordering|Equiv)|(Less|Equal|Greater)|(Container|Mutable|Map|MutableMap|Set|MutableSet)|(FromIterator|Extendable)|(Iterator|DoubleEndedIterator|RandomAccessIterator|CloneableIterator)|(OrdIterator|MutableDoubleEndedIterator|ExactSize)|(Num|NumCast|CheckedAdd|CheckedSub|CheckedMul)|(Signed|Unsigned|Round)|(Primitive|Int|Float|ToPrimitive|FromPrimitive)|(GenericPath|Path|PosixPath|WindowsPath)|(RawPtr)|(Buffer|Writer|Reader|Seek)|(Str|StrVector|StrSlice|OwnedStr|IntoMaybeOwned|StrBuf)|(ToStr|IntoStr)|(Tuple1|Tuple2|Tuple3|Tuple4)|(Tuple5|Tuple6|Tuple7|Tuple8)|(Tuple9|Tuple10|Tuple11|Tuple12)|(ImmutableEqVector|ImmutableTotalOrdVector|ImmutableCloneableVector)|(OwnedVector|OwnedCloneableVector|OwnedEqVector)|(MutableVector|MutableTotalOrdVector)|(Vector|VectorVector|CloneableVector|ImmutableVector)))\> 0:identifier
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _rust_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _rust_indent_on_new_line %~
eval -draft -itersel %_
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _rust_filter_around_selections <ret> }
# copy // comments prefix and following white spaces
try %{ exec -draft k x s ^\h*\K//\h* <ret> y j p }
# indent after lines ending with { or (
try %[ exec -draft k <a-x> <a-k> [{(]\h*$ <ret> j <a-gt> ]
# align to opening paren of previous line
try %{ exec -draft [( <a-k> \`\([^\n]+\n[^\n]*\n?\' <ret> s \`\(\h*.|.\' <ret> & }
# indent after visibility specifier
try %[ exec -draft k <a-x> <a-k> ^\h*(public|private|protected):\h*$ <ret> j <a-gt> ]
# indent after if|else|while|for
try %[ exec -draft <space> <a-F> ) M B <a-k> \`(if|else|while|for)\h*\(.*\)\h*\n\h*\n?\' <ret> s \`|.\' <ret> 1<a-&> 1<a-space> <a-gt> ]
_
~
def -hidden _rust_indent_on_opening_curly_brace %[
eval -draft -itersel %_
# align indent with opening paren when { is entered on a new line after the closing paren
try %[ exec -draft h <a-F> ) M <a-k> \`\(.*\)\h*\n\h*\{\' <ret> s \`|.\' <ret> 1<a-&> ]
_
]
def -hidden _rust_indent_on_closing_curly_brace %[
eval -draft -itersel %_
# align to opening curly brace when alone on a line
try %[ exec -draft <a-h> <a-k> ^\h+\}$ <ret> h m s \`|.\' <ret> 1<a-&> ]
# add ; after } if class or struct definition
try %[ exec -draft h m <space> <a-?> (class|struct) <ret> <a-k> \`(class|struct)[^{}\n]+(\n)?\s*\{\' <ret> <a-space> m a \; <esc> ]
_
]
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=rust %[
addhl ref rust
hook window InsertEnd .* -group rust-hooks _rust_filter_around_selections
hook window InsertChar \n -group rust-indent _rust_indent_on_new_line
hook window InsertChar \{ -group rust-indent _rust_indent_on_opening_curly_brace
hook window InsertChar \} -group rust-indent _rust_indent_on_closing_curly_brace
]
hook global WinSetOption filetype=(?!rust).* %{
rmhl rust
rmhooks window rust-indent
rmhooks window rust-hooks
}

71
rc/sass.kak Normal file
View File

@ -0,0 +1,71 @@
# http://sass-lang.com
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-sass %{
set buffer filetype sass
}
hook global BufCreate .*[.](sass) %{
set buffer filetype sass
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / regions -default code sass \
string '"' (?<!\\)(\\\\)*" '' \
string "'" "'" '' \
comment '/' '$' ''
addhl -group /sass/string fill string
addhl -group /sass/comment fill comment
addhl -group /sass/code regex [*]|[#.][A-Za-z][A-Za-z0-9_-]* 0:identifier
addhl -group /sass/code regex &|@[A-Za-z][A-Za-z0-9_-]* 0:meta
addhl -group /sass/code regex (#[0-9A-Fa-f]+)|((\d*\.)?\d+(em|px)) 0:value
addhl -group /sass/code regex ([A-Za-z][A-Za-z0-9_-]*)\h*: 1:keyword
addhl -group /sass/code regex :(before|after) 0:attribute
addhl -group /sass/code regex !important 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _sass_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _sass_indent_on_new_line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _sass_filter_around_selections <ret> }
# copy '/' comment prefix and following white spaces
try %{ exec -draft k x s ^\h*\K/\h* <ret> y j p }
# avoid indent after properties and comments
try %{ exec -draft k x <a-K> [:/] <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=sass %{
addhl ref sass
hook window InsertEnd .* -group sass-hooks _sass_filter_around_selections
hook window InsertChar \n -group sass-indent _sass_indent_on_new_line
}
hook global WinSetOption filetype=(?!sass).* %{
rmhl sass
rmhooks window sass-indent
rmhooks window sass-hooks
}

48
rc/scss.kak Normal file
View File

@ -0,0 +1,48 @@
# http://sass-lang.com
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# require css.kak
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-scss %{
set buffer filetype scss
}
hook global BufCreate .*[.](scss) %{
set buffer filetype scss
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / group scss
addhl -group /scss ref css
addhl -group /scss regex @[A-Za-z][A-Za-z0-9_-]* 0:meta
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _scss_filter_around_selections _css_filter_around_selections
def -hidden _scss_indent_on_new_line _css_indent_on_new_line
def -hidden _scss_indent_on_closing_curly_brace _css_indent_on_closing_curly_brace
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=scss %[
addhl ref scss
hook window InsertEnd .* -group scss-hooks _scss_filter_around_selections
hook window InsertChar \n -group scss-indent _scss_indent_on_new_line
hook window InsertChar \} -group scss-indent _scss_indent_on_closing_curly_brace
]
hook global WinSetOption filetype=(?!scss).* %{
rmhl scss
rmhooks window scss-indent
rmhooks window scss-hooks
}