2017-01-17 09:48:48 +01:00
|
|
|
# http://ponylang.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](pony) %{
|
2017-11-03 08:34:41 +01:00
|
|
|
set-option buffer filetype pony
|
2017-01-17 09:48:48 +01:00
|
|
|
}
|
|
|
|
|
2019-04-10 05:54:19 +02:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=pony %{
|
2019-03-13 06:24:33 +01:00
|
|
|
require-module pony
|
2019-04-10 05:54:19 +02:00
|
|
|
|
|
|
|
set-option window static_words %opt{pony_static_words}
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
hook window InsertChar \n -group pony-insert pony-insert-on-new-line
|
2019-04-10 05:54:19 +02:00
|
|
|
hook window InsertChar \n -group pony-indent pony-indent-on-new-line
|
|
|
|
# cleanup trailing whitespaces on current line insert end
|
2022-03-16 23:20:07 +01:00
|
|
|
hook window ModeChange pop:insert:.* -group pony-trim-indent %{ try %{ execute-keys -draft <semicolon> x s ^\h+$ <ret> d } }
|
2019-04-10 05:54:19 +02:00
|
|
|
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window pony-.+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group pony-highlight global WinSetOption filetype=pony %{
|
|
|
|
add-highlighter window/pony ref pony
|
|
|
|
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter pony }
|
2019-03-13 06:24:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
provide-module pony %{
|
|
|
|
|
2017-01-17 09:48:48 +01:00
|
|
|
# Highlighters & Completion
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/pony regions
|
|
|
|
add-highlighter shared/pony/code default-region group
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/pony/triple_string region '"""' '"""' fill string
|
|
|
|
add-highlighter shared/pony/double_string region '"' (?<!\\)(\\\\)*" fill string
|
|
|
|
add-highlighter shared/pony/comment region '/\*' '\*/' fill comment
|
|
|
|
add-highlighter shared/pony/line_comment region '//' '$' fill comment
|
2017-01-17 09:48:48 +01:00
|
|
|
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %sh{
|
2017-01-17 09:48:48 +01:00
|
|
|
# Grammar
|
|
|
|
values="true|false|None|this"
|
|
|
|
meta='use'
|
|
|
|
# Keyword list is collected using `keyword.kwlist` from `keyword`
|
|
|
|
keywords="and|as|or|break|match|continue|else|try|in|return|end|for|is"
|
|
|
|
keywords="${keywords}|recover|consume|error|do|then|if|while"
|
|
|
|
func_decl="new|fun|be|lambda"
|
|
|
|
capabilities="iso|ref|box|tag|val|trn"
|
2017-01-20 13:51:25 +01:00
|
|
|
struct="class|actor|interface|trait|primitive|type|var|let|embed"
|
2017-01-17 09:48:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Add the language's grammar to the static completion list
|
2018-06-17 05:30:40 +02:00
|
|
|
static_words="${values} ${meta} ${keywords} ${types_decl} ${capabilities}"
|
|
|
|
static_words="${static_words} ${struct}"
|
2019-04-10 05:54:19 +02:00
|
|
|
printf %s\\n "declare-option str-list pony_static_words ${static_words}" | tr '|' ' '
|
2017-01-17 09:48:48 +01:00
|
|
|
|
|
|
|
# Highlight keywords
|
|
|
|
printf %s "
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/pony/code/ regex '\b(${values})\b' 0:value
|
|
|
|
add-highlighter shared/pony/code/ regex '\b(${meta})\b' 0:meta
|
|
|
|
add-highlighter shared/pony/code/ regex '\b(${func_decl})(\s+(${capabilities}))?(\s+\w+)\(' 1:type 3:builtin 4:builtin
|
|
|
|
add-highlighter shared/pony/code/ regex '\b(${func_decl})\b' 0:type
|
|
|
|
add-highlighter shared/pony/code/ regex '=>' 0:type
|
|
|
|
add-highlighter shared/pony/code/ regex '\b(${keywords})\b' 0:keyword
|
|
|
|
add-highlighter shared/pony/code/ regex ';' 0:keyword
|
|
|
|
add-highlighter shared/pony/code/ regex '^\s*|' 0:keyword
|
|
|
|
add-highlighter shared/pony/code/ regex '\b(${struct})\b' 0:variable
|
|
|
|
add-highlighter shared/pony/code/ regex '\b(${capabilities})\b(!|^)?' 1:builtin 2:builtin
|
2017-01-17 09:48:48 +01:00
|
|
|
"
|
|
|
|
|
|
|
|
# Highlight types and attributes
|
|
|
|
printf %s "
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/pony/code/ regex '@[\w_]+\b' 0:attribute
|
2017-01-17 09:48:48 +01:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2021-04-17 10:17:01 +02:00
|
|
|
define-command -hidden pony-insert-on-new-line %{
|
|
|
|
evaluate-commands -draft -itersel %{
|
|
|
|
# copy // comments prefix and following white spaces
|
|
|
|
try %{ execute-keys -draft k x s ^\h*//\h* <ret> y jgh P }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden pony-indent-on-new-line %{
|
2017-11-03 09:09:45 +01:00
|
|
|
evaluate-commands -draft -itersel %{
|
2017-01-17 09:48:48 +01:00
|
|
|
# preserve previous line indent
|
2022-04-15 00:14:17 +02:00
|
|
|
try %{ execute-keys -draft , K <a-&> }
|
2017-01-17 09:48:48 +01:00
|
|
|
# cleanup trailing whitespaces from previous line
|
2022-03-16 23:20:07 +01:00
|
|
|
try %{ execute-keys -draft k x s \h+$ <ret> d }
|
2017-01-17 09:48:48 +01:00
|
|
|
# indent after line ending with :
|
2022-04-15 00:14:17 +02:00
|
|
|
try %{ execute-keys -draft , k x <a-k> (\b(?:do|try|then|else)|:|=>)$ <ret> j <a-gt> }
|
2017-01-17 09:48:48 +01:00
|
|
|
# else, end are always de-indented
|
2022-04-15 00:14:17 +02:00
|
|
|
try %{ execute-keys -draft , k x <a-k> \b(else|end):$ <ret> k x s ^\h* <ret> y j x <a-k> ^<c-r>" <ret> J <a-lt> }
|
2017-01-17 09:48:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-13 06:24:33 +01:00
|
|
|
}
|