2014-07-15 01:08:26 +04:00
|
|
|
# http://coffeescript.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](coffee) %{
|
2017-11-03 10:34:41 +03:00
|
|
|
set-option buffer filetype coffee
|
2014-07-15 01:08:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter shared/ regions -default code coffee \
|
2014-07-15 01:08:26 +04:00
|
|
|
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
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter shared/coffee/double_string fill string
|
|
|
|
add-highlighter shared/coffee/double_string regions regions interpolation \Q#{ \} \{
|
|
|
|
add-highlighter shared/coffee/double_string/regions/interpolation fill meta
|
|
|
|
add-highlighter shared/coffee/single_string fill string
|
|
|
|
add-highlighter shared/coffee/regex fill meta
|
|
|
|
add-highlighter shared/coffee/regex regions regions interpolation \Q#{ \} \{
|
|
|
|
add-highlighter shared/coffee/regex/regions/interpolation fill meta
|
|
|
|
add-highlighter shared/coffee/comment fill comment
|
2014-07-15 01:08:26 +04:00
|
|
|
|
|
|
|
# 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
|
2017-10-28 06:00:51 +03:00
|
|
|
add-highlighter shared/coffee/code regex [$@]\w* 0:variable
|
|
|
|
add-highlighter shared/coffee/code regex \b(Array|Boolean|Date|Function|Number|Object|RegExp|String)\b 0:type
|
|
|
|
add-highlighter shared/coffee/code regex \b(document|false|no|null|off|on|parent|self|this|true|undefined|window|yes)\b 0:value
|
|
|
|
add-highlighter shared/coffee/code regex \b(and|is|isnt|not|or)\b 0:operator
|
|
|
|
add-highlighter shared/coffee/code regex \b(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)\b 0:keyword
|
2014-07-15 01:08:26 +04:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden coffee-filter-around-selections %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -draft -itersel %{
|
|
|
|
execute-keys <a-x>
|
2016-02-03 11:05:58 +03:00
|
|
|
# remove trailing white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft s \h + $ <ret> d }
|
2016-02-03 11:05:58 +03:00
|
|
|
}
|
2014-07-15 01:08:26 +04:00
|
|
|
}
|
|
|
|
|
2017-11-03 10:34:41 +03:00
|
|
|
define-command -hidden coffee-indent-on-new-line %{
|
2017-11-03 11:09:45 +03:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-01-11 16:56:48 +03:00
|
|
|
# copy '#' comment prefix and following white spaces
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k <a-x> s '^\h*\K#\h*' <ret> y gh j P }
|
2014-07-15 01:08:26 +04:00
|
|
|
# preserve previous line indent
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft \; K <a-&> }
|
2014-07-15 01:08:26 +04:00
|
|
|
# filter previous line
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k : coffee-filter-around-selections <ret> }
|
2016-02-03 11:05:58 +03:00
|
|
|
# indent after start structure
|
2017-11-03 11:09:45 +03:00
|
|
|
try %{ execute-keys -draft k <a-x> <a-k> ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ <ret> j <a-gt> }
|
2014-07-15 01:08:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
hook -group coffee-highlight global WinSetOption filetype=coffee %{ add-highlighter window ref coffee }
|
2014-07-15 01:08:26 +04:00
|
|
|
|
2016-09-25 16:15:07 +03:00
|
|
|
hook global WinSetOption filetype=coffee %{
|
2018-01-21 02:35:05 +03:00
|
|
|
hook window ModeChange insert:.* -group coffee-hooks coffee-filter-around-selections
|
2017-01-13 03:56:30 +03:00
|
|
|
hook window InsertChar \n -group coffee-indent coffee-indent-on-new-line
|
2014-07-15 01:08:26 +04:00
|
|
|
}
|
|
|
|
|
2017-10-28 06:00:51 +03:00
|
|
|
hook -group coffee-highlight global WinSetOption filetype=(?!coffee).* %{ remove-highlighter window/coffee }
|
2016-09-28 09:45:01 +03:00
|
|
|
|
2014-07-15 01:08:26 +04:00
|
|
|
hook global WinSetOption filetype=(?!coffee).* %{
|
2017-01-04 03:07:45 +03:00
|
|
|
remove-hooks window coffee-indent
|
|
|
|
remove-hooks window coffee-hooks
|
2014-07-15 01:08:26 +04:00
|
|
|
}
|