Merge various language support scripts

This commit is contained in:
Maxime Coste 2014-07-07 23:59:20 +01:00
5 changed files with 329 additions and 3 deletions

View File

@ -16,9 +16,9 @@ hook global BufCreate .*[.](fish) %{
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / multi_region -default code fish \
double_string (^|\h)" (?<!\\)(\\\\)*" '' \
single_string (^|\h)' (?<!\\)(\\\\)*' '' \
comment (^|\h)# $ ''
double_string '"' (?<!\\)(\\\\)*" '' \
single_string "'" "'" '' \
comment '#' '$' ''
addhl -group /fish/double_string fill string
addhl -group /fish/double_string regex (\$\w+)|(\{\$\w+\}) 0:identifier

82
rc/javascript.kak Normal file
View File

@ -0,0 +1,82 @@
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-javascript %{
set buffer filetype javascript
}
hook global BufCreate .*[.](js) %{
set buffer filetype javascript
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / multi_region -default code javascript \
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 /javascript/double_string fill string
addhl -group /javascript/single_string fill string
addhl -group /javascript/regex fill macro
addhl -group /javascript/comment fill comment
addhl -group /javascript/code regex \<(document|false|null|parent|self|this|true|undefined|window)\> 0:value
addhl -group /javascript/code regex \<(Array|Boolean|Date|Function|Number|Object|RegExp|String)\> 0:type
# Keywords are collected at
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
addhl -group /javascript/code regex \<(break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|return|super|switch|throw|try|typeof|var|void|while|with|yield)\> 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _javascript_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _javascript_indent_on_char "
eval -draft -itersel '
# indent closer token to its opener
try %_ exec -draft gh <a-k> ^\h*[]}] <ret> m <a-&> _
'
"
def -hidden _javascript_indent_on_new_line "
eval -draft -itersel '
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _javascript_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 beginning / ending with opener token
try %_ exec -draft k x <a-k> ^\h*[[{]|[[{]$ <ret> j <a-gt> _
'
"
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=javascript %{
addhl ref javascript
hook window InsertEnd .* -group javascript-hooks _javascript_filter_around_selections
hook window InsertChar .* -group javascript-indent _javascript_indent_on_char
hook window InsertChar \n -group javascript-indent _javascript_indent_on_new_line
}
hook global WinSetOption filetype=(?!javascript).* %{
rmhl javascript
rmhooks window javascript-indent
rmhooks window javascript-hooks
}

73
rc/python.kak Normal file
View File

@ -0,0 +1,73 @@
# http://python.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-python %{
set buffer filetype python
}
hook global BufCreate .*[.](py) %{
set buffer filetype python
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / multi_region -default code python \
double_string '"""' '"""' '' \
single_string "'''" "'''" '' \
double_string '"' (?<!\\)(\\\\)*" '' \
single_string "'" "'" '' \
comment '#' '$' ''
addhl -group /python/double_string fill string
addhl -group /python/single_string fill string
addhl -group /python/comment fill comment
addhl -group /python/code regex \<(True|False|None)\> 0:value
addhl -group /python/code regex \<(import|from)\> 0:macro
# Keyword list is collected using `keyword.kwlist` from `keyword`
addhl -group /python/code regex \<(and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|global|if|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield)\> 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _python_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _python_indent_on_new_line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _python_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 :
try %{ exec -draft <space> k x <a-k> :$ <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=python %{
addhl ref python
hook window InsertEnd .* -group python-hooks _python_filter_around_selections
hook window InsertChar \n -group python-indent _python_indent_on_new_line
}
hook global WinSetOption filetype=(?!python).* %{
rmhl python
rmhooks window python-indent
rmhooks window python-hooks
}

102
rc/ruby.kak Normal file
View File

@ -0,0 +1,102 @@
# http://ruby-lang.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-ruby %{
set buffer filetype ruby
}
hook global BufCreate .*(([.](rb))|(irbrc)|(pryrc)|(Capfile|[.]cap)|(Gemfile)|(Guardfile)|(Rakefile|[.]rake)|(Thorfile|[.]thor)|(Vagrantfile)) %{
set buffer filetype ruby
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / multi_region -default code ruby \
double_string '"' (?<!\\)(\\\\)*" '' \
single_string "'" "'" '' \
backtick '`' (?<!\\)(\\\\)*` '' \
regex '/' (?<!\\)(\\\\)*/[imox]* '' \
comment '#' '$' '' \
comment ^begin= ^=end '' \
literal '%[iqrswxIQRSWX]\Q(' '\Q)' '' \
literal '%[iqrswxIQRSWX]\Q{' '\Q}' '' \
literal '%[iqrswxIQRSWX]\Q[' '\Q]' '' \
literal '%[iqrswxIQRSWX]\Q<' '\Q>' ''
# Regular expression flags are: i → ignore case, m → multi-lines, o → only interpolate #{} blocks once, x → extended mode (ignore white spaces)
# Literals are: i → array of symbols, q → string, r → regular expression, s → symbol, w → array of words, x → capture shell result
addhl -group /ruby/double_string fill string
addhl -group /ruby/double_string region interpolation \Q#{ \} \{
addhl -group /ruby/double_string/interpolation/content fill macro
addhl -group /ruby/single_string fill string
addhl -group /ruby/backtick fill macro
addhl -group /ruby/backtick region interpolation \Q#{ \} \{
addhl -group /ruby/backtick/interpolation/content fill macro
addhl -group /ruby/regex fill macro
addhl -group /ruby/regex region interpolation \Q#{ \} \{
addhl -group /ruby/regex/interpolation/content fill macro
addhl -group /ruby/comment fill comment
addhl -group /ruby/literal fill macro
addhl -group /ruby/code regex ([$@][a-z]\w+)|(\W\K:[a-z]\w+[=?!]?) 0:identifier
addhl -group /ruby/code regex \<(require|include)\>|\<([a-z]\w+:) 0:macro
addhl -group /ruby/code regex \<(attr_(reader|writer|accessor))\> 0:attribute
# Keywords are collected searching for keyword_ at
# https://github.com/ruby/ruby/blob/trunk/parse.y
addhl -group /ruby/code regex \<(alias|and|begin|break|case|class|def|defined|do|else|elsif|end|ensure|false|for|if|in|module|next|nil|not|or|redo|rescue|retry|return|self|super|then|true|undef|unless|until|when|while|yield)\> 0:keyword
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _ruby_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _ruby_indent_on_char %{
eval -draft -itersel %{
# deindent on (else|elsif|end|rescue|when) keyword insertion
try %{ exec -draft <space> <a-i>w <a-k> (else|elsif|end|rescue|when) <ret> <a-lt> }
}
}
def -hidden _ruby_indent_on_new_line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _ruby_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 (else|elsif|rescue|when) keywords
try %_ exec -draft <space> k x <a-k> (else|elsif|rescue|when) <ret> j <a-gt> _
# indent after (begin|case|class|def|do|if|loop|module|unless|until|while) keywords and add 'end' keyword
try %{ exec -draft <space> k x <a-k> (begin|case|class|def|do|(?<!els)if|loop|module|unless|until|while) <ret> x y p j a end <esc> k <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=ruby %{
addhl ref ruby
hook window InsertEnd .* -group ruby-hooks _ruby_filter_around_selections
hook window InsertChar .* -group ruby-indent _ruby_indent_on_char
hook window InsertChar \n -group ruby-indent _ruby_indent_on_new_line
}
hook global WinSetOption filetype=(?!ruby).* %{
rmhl ruby
rmhooks window ruby-indent
rmhooks window ruby-hooks
}

69
rc/yaml.kak Normal file
View File

@ -0,0 +1,69 @@
# http://yaml.org
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
# Detection
# ‾‾‾‾‾‾‾‾‾
hook global BufSetOption mimetype=text/x-yaml %{
set buffer filetype yaml
}
hook global BufCreate .*[.](yaml) %{
set buffer filetype yaml
}
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
addhl -group / multi_region -default code yaml \
double_string '"' (?<!\\)(\\\\)*" '' \
single_string "'" "'" '' \
comment '#' '$' ''
addhl -group /yaml/double_string fill string
addhl -group /yaml/single_string fill string
addhl -group /yaml/comment fill comment
addhl -group /yaml/code regex ^(---|\.\.\.)$ 0:macro
addhl -group /yaml/code regex ^(\h*:\w*) 0:keyword
addhl -group /yaml/code regex \<(true|false|null)\> 0:value
# Commands
# ‾‾‾‾‾‾‾‾
def -hidden _yaml_filter_around_selections %{
eval -draft -itersel %{
exec <a-x>
# remove trailing white spaces
try %{ exec -draft s \h+$ <ret> d }
}
}
def -hidden _yaml_indent_on_new_line %{
eval -draft -itersel %{
# preserve previous line indent
try %{ exec -draft <space> K <a-&> }
# filter previous line
try %{ exec -draft k : _yaml_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 :
try %{ exec -draft <space> k x <a-k> :$ <ret> j <a-gt> }
}
}
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
hook global WinSetOption filetype=yaml %{
addhl ref yaml
hook window InsertEnd .* -group yaml-hooks _yaml_filter_around_selections
hook window InsertChar \n -group yaml-indent _yaml_indent_on_new_line
}
hook global WinSetOption filetype=(?!yaml).* %{
rmhl yaml
rmhooks window yaml-indent
rmhooks window yaml-hooks
}