2017-01-17 09:48:48 +01:00
|
|
|
# http://ponylang.org
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
hook global BufCreate .*[.](pony) %{
|
|
|
|
set buffer filetype pony
|
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters & Completion
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
addhl shared/ regions -default code pony \
|
2017-01-17 09:48:48 +01:00
|
|
|
double_string '"""' '"""' '' \
|
|
|
|
double_string '"' (?<!\\)(\\\\)*" '' \
|
|
|
|
comment '/\*' '\*/' '' \
|
|
|
|
comment '//' '$' ''
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
addhl shared/pony/double_string fill string
|
|
|
|
# addhl shared/pony/single_string fill string
|
|
|
|
addhl shared/pony/comment fill comment
|
2017-01-17 09:48:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
%sh{
|
|
|
|
# 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
|
|
|
|
static_words="${values}:${meta}:${keywords}:${types_decl}:${capabilities}"
|
2017-01-20 13:51:25 +01:00
|
|
|
static_words="${static_words}::${struct}"
|
2017-01-17 09:48:48 +01:00
|
|
|
printf %s\\n "hook global WinSetOption filetype=pony %{
|
|
|
|
set window static_words '${static_words}'
|
|
|
|
}" | sed 's,|,:,g'
|
|
|
|
|
|
|
|
# Highlight keywords
|
|
|
|
printf %s "
|
2017-10-28 05:00:51 +02:00
|
|
|
addhl shared/pony/code regex '\b(${values})\b' 0:value
|
|
|
|
addhl shared/pony/code regex '\b(${meta})\b' 0:meta
|
|
|
|
addhl shared/pony/code regex '\b(${func_decl})(\s+(${capabilities}))?(\s+\w+)\(' 1:type 3:builtin 4:builtin
|
|
|
|
addhl shared/pony/code regex '\b(${func_decl})\b' 0:type
|
|
|
|
addhl shared/pony/code regex '=>' 0:type
|
|
|
|
addhl shared/pony/code regex '\b(${keywords})\b' 0:keyword
|
|
|
|
addhl shared/pony/code regex ';' 0:keyword
|
|
|
|
addhl shared/pony/code regex '^\s*|' 0:keyword
|
|
|
|
addhl shared/pony/code regex '\b(${struct})\b' 0:variable
|
|
|
|
addhl 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 "
|
2017-10-28 05:00:51 +02:00
|
|
|
addhl shared/pony/code regex '@[\w_]+\b' 0:attribute
|
2017-01-17 09:48:48 +01:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
def -hidden pony-indent-on-new-line %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
# preserve previous line indent
|
|
|
|
try %{ exec -draft <space> K <a-&> }
|
|
|
|
# cleanup trailing whitespaces from previous line
|
|
|
|
try %{ exec -draft k <a-x> s \h+$ <ret> d }
|
|
|
|
# copy '//' comment prefix and following white spaces
|
|
|
|
# try %{ exec -draft k x s ^\h*//\h* <ret> y jgh P }
|
|
|
|
# indent after line ending with :
|
2017-01-20 13:51:25 +01:00
|
|
|
try %{ exec -draft <space> k x <a-k> (do|try|then|else|:|=>)$ <ret> j <a-gt> }
|
2017-01-17 09:48:48 +01:00
|
|
|
# else, end are always de-indented
|
|
|
|
try %{ exec -draft <space> k x <a-k> (else|end):$ <ret> k x s ^\h* <ret> y j x <a-k> ^<c-r>" <ret> J <a-lt> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-10-28 05:00:51 +02:00
|
|
|
hook -group pony-highlight global WinSetOption filetype=pony %{ addhl window ref pony }
|
2017-01-17 09:48:48 +01:00
|
|
|
|
|
|
|
hook global WinSetOption filetype=pony %{
|
|
|
|
hook window InsertChar \n -group pony-indent pony-indent-on-new-line
|
|
|
|
# cleanup trailing whitespaces on current line insert end
|
|
|
|
hook window InsertEnd .* -group pony-indent %{ try %{ exec -draft \; <a-x> s ^\h+$ <ret> d } }
|
|
|
|
}
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=pony %{
|
|
|
|
set buffer tabstop 2
|
|
|
|
set buffer indentwidth 2
|
|
|
|
}
|
|
|
|
|
|
|
|
hook -group pony-highlight global WinSetOption filetype=(?!pony).* %{ rmhl pony }
|
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!pony).* %{
|
|
|
|
rmhooks window pony-indent
|
|
|
|
}
|