2014-07-14 23:08:26 +02:00
|
|
|
# http://coffeescript.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](coffee) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype coffee
|
2014-07-14 23:08:26 +02:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=coffee %{
|
2019-03-13 22:00:59 +01:00
|
|
|
require-module coffee
|
2019-04-12 00:54:58 +02:00
|
|
|
|
2022-04-30 11:22:47 +02:00
|
|
|
hook window ModeChange pop:insert:.* -group coffee-trim-indent coffee-trim-indent
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group coffee-insert coffee-insert-on-new-line
|
2019-04-12 00:54:58 +02:00
|
|
|
hook window InsertChar \n -group coffee-indent coffee-indent-on-new-line
|
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window coffee-.+ }
|
2019-03-13 22:00:59 +01:00
|
|
|
}
|
|
|
|
|
2019-04-12 00:54:58 +02:00
|
|
|
hook -group coffee-highlight global WinSetOption filetype=coffee %{
|
|
|
|
add-highlighter window/coffee ref coffee
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/coffee }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
provide-module coffee %[
|
|
|
|
|
2014-07-14 23:08:26 +02:00
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/coffee regions
|
|
|
|
add-highlighter shared/coffee/code default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/coffee/single_string region "'" "'" fill string
|
|
|
|
add-highlighter shared/coffee/single_string_alt region "'''" "'''" fill string
|
|
|
|
add-highlighter shared/coffee/double_string region '"' (?<!\\)(\\\\)*" regions
|
|
|
|
add-highlighter shared/coffee/double_string_alt region '"""' '"""' ref shared/coffee/double_string
|
|
|
|
add-highlighter shared/coffee/regex region '/' (?<!\\)(\\\\)*/[gimy]* regions
|
|
|
|
add-highlighter shared/coffee/regex_alt region '///' ///[gimy]* ref shared/coffee/regex
|
|
|
|
add-highlighter shared/coffee/comment1 region '#' '$' fill comment
|
|
|
|
add-highlighter shared/coffee/comment2 region '###' '###' fill comment
|
2014-07-14 23:08:26 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/coffee/double_string/base default-region fill string
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/coffee/double_string/interpolation region -recurse \{ \Q#{ \} fill meta
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/coffee/regex/base default-region fill meta
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/coffee/regex/interpolation region -recurse \{ \Q#{ \} fill meta
|
2014-07-14 23:08:26 +02: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
|
2018-07-01 11:53:35 +02: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-14 23:08:26 +02:00
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-12-19 10:10:26 +01:00
|
|
|
define-command -hidden coffee-trim-indent %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2022-03-16 23:20:07 +01:00
|
|
|
execute-keys x
|
2016-02-03 09:05:58 +01:00
|
|
|
# remove trailing white spaces
|
2017-11-03 09:09:45 +01:00
|
|
|
try %{ execute-keys -draft s \h + $ <ret> d }
|
2016-02-03 09:05:58 +01:00
|
|
|
}
|
2014-07-14 23:08:26 +02:00
|
|
|
}
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden coffee-insert-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-01-11 14:56:48 +01:00
|
|
|
# copy '#' comment prefix and following white spaces
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x s '^\h*\K#\h*' <ret> y gh j P }
|
2021-04-17 10:17:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define-command -hidden coffee-indent-on-new-line %{
|
|
|
|
evaluate-commands -draft -itersel %{
|
2014-07-14 23:08:26 +02:00
|
|
|
# preserve previous line indent
|
2019-10-22 11:02:06 +02:00
|
|
|
try %{ execute-keys -draft <semicolon> K <a-&> }
|
2014-07-14 23:08:26 +02:00
|
|
|
# filter previous line
|
2018-12-19 10:10:26 +01:00
|
|
|
try %{ execute-keys -draft k : coffee-trim-indent <ret> }
|
2016-02-03 09:05:58 +01:00
|
|
|
# indent after start structure
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x <a-k> ^ \h * (case|catch|class|else|finally|for|function|if|switch|try|while|with) \b | (=|->) $ <ret> j <a-gt> }
|
2014-07-14 23:08:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 22:00:59 +01:00
|
|
|
]
|