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}
|
|
|
|
|
|
|
|
# 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 } }
|
2024-01-11 21:43:27 +01:00
|
|
|
hook window InsertChar \n -group pony-indent pony-indent-on-new-line
|
|
|
|
hook window InsertChar \n -group pony-insert pony-insert-on-new-line
|
|
|
|
|
|
|
|
set-option buffer extra_word_chars '_' "'"
|
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
|
|
|
}
|
|
|
|
|
2024-01-11 21:43:27 +01:00
|
|
|
provide-module pony %§
|
2019-03-13 06:24:33 +01:00
|
|
|
|
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
|
2017-01-17 09:48:48 +01:00
|
|
|
|
2024-01-11 21:43:27 +01:00
|
|
|
add-highlighter shared/pony/comment region '/\*' '\*/' fill comment
|
|
|
|
add-highlighter shared/pony/line_comment region '//' '$' fill comment
|
|
|
|
|
|
|
|
# String literals
|
|
|
|
add-highlighter shared/pony/string region -match-capture '("""|")' '(?<!\\)(?:\\\\)*("""|")' group
|
|
|
|
add-highlighter shared/pony/string/ fill string
|
|
|
|
add-highlighter shared/pony/string/ regex '(?:\\a|\\b|\\e|\\f|\\n|\\r|\\t||\\v|\\\\|\\''|\\0|\\x[0-9a-fA-F]{2}|\\u[0-9a-fA-F]{4}|\\u[0-9a-fA-F]{6})' 0:meta
|
|
|
|
|
|
|
|
# Character literals
|
|
|
|
# negative lookbehind to account for variables with prime such as myvar' or myvar''
|
|
|
|
add-highlighter shared/pony/character region "(?<![a-z0-9'])'" (?<!\\)(\\\\)*' group
|
|
|
|
add-highlighter shared/pony/character/ fill string
|
|
|
|
add-highlighter shared/pony/character/ regex '(?:\\a|\\b|\\e|\\f|\\n|\\r|\\t||\\v|\\\\|\\''|\\0|\\x[0-9a-fA-F]{2})' 0:meta
|
|
|
|
|
|
|
|
# Operators
|
|
|
|
add-highlighter shared/pony/code/ regex '=|\+|-|\*|/|%|%%|<<|>>|==|!=|<|<=|>=|>|=>|;' 0:operator
|
|
|
|
add-highlighter shared/pony/code/ regex '(\+|-|\*|/|%|%%|<<|>>|==|!=|<|<=|>=|>)~' 0:operator
|
|
|
|
add-highlighter shared/pony/code/ regex '(\+|-|\*|/|%|%%)\?' 0:operator
|
|
|
|
add-highlighter shared/pony/code/ regex '^\h*|' 0:operator
|
|
|
|
add-highlighter shared/pony/code/ regex '\b_\b' 0:operator
|
|
|
|
|
|
|
|
# Integer literals
|
|
|
|
add-highlighter shared/pony/code/ regex '\b[0-9](_?[0-9])*\b' 0:value
|
|
|
|
add-highlighter shared/pony/code/ regex '\b0x[0-9a-fA-F](_?[0-9a-fA-F])*\b' 0:value
|
|
|
|
add-highlighter shared/pony/code/ regex '\b0b[01](_?[01])*\b' 0:value
|
|
|
|
|
|
|
|
# Float literals
|
|
|
|
add-highlighter shared/pony/code/ regex '\b[0-9]+\.[0-9]+(?:[eE][-+]?[0-9]+)?\b' 0:value
|
|
|
|
add-highlighter shared/pony/code/ regex '\b[0-9]+[eE][-+]?[0-9]+\b' 0:value
|
|
|
|
|
|
|
|
# Type literals
|
|
|
|
add-highlighter shared/pony/code/ regex '\b_?[A-Z][A-Za-z0-9]*\b' 0:type
|
|
|
|
|
|
|
|
# Literal words are highlighted below to also allow for autocompletion by appending
|
|
|
|
# them to static_words.
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %sh{
|
2017-01-17 09:48:48 +01:00
|
|
|
# Grammar
|
2024-01-11 21:43:27 +01:00
|
|
|
values="true|false|this"
|
2017-01-17 09:48:48 +01:00
|
|
|
meta='use'
|
|
|
|
# Keyword list is collected using `keyword.kwlist` from `keyword`
|
2024-01-11 21:43:27 +01:00
|
|
|
keywords="as|break|match|continue|else|elseif|try|in|return|end|for|is"
|
|
|
|
keywords="${keywords}|recover|consume|error|do|then|if|while|where|with"
|
|
|
|
keywords="${keywords}|class|struct|object|actor|interface|trait|primitive"
|
|
|
|
keywords="${keywords}|type|var|let|embed|repeat|until|addressof"
|
|
|
|
func_decl="new|fun|be"
|
2017-01-17 09:48:48 +01:00
|
|
|
capabilities="iso|ref|box|tag|val|trn"
|
2024-01-11 21:43:27 +01:00
|
|
|
operators="and|or|xor|not"
|
|
|
|
builtin_types="String|None|Any|Array"
|
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}"
|
2024-01-11 21:43:27 +01:00
|
|
|
static_words="${static_words} ${operators} ${builtin_types}"
|
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
|
2024-01-11 21:43:27 +01:00
|
|
|
# The (?!') ensures that keywords with prime are highlighted as usual, for example try'
|
2017-01-17 09:48:48 +01:00
|
|
|
printf %s "
|
2024-01-11 21:43:27 +01:00
|
|
|
add-highlighter shared/pony/code/ regex \b(${values})\b(?!') 0:value
|
|
|
|
add-highlighter shared/pony/code/ regex \b(${operators})\b(?!') 0:operator
|
|
|
|
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:keyword 3:attribute 4:function
|
|
|
|
add-highlighter shared/pony/code/ regex \b(${func_decl})\b(?!') 0:keyword
|
|
|
|
add-highlighter shared/pony/code/ regex \b(${keywords})\b(?!') 0:keyword
|
|
|
|
add-highlighter shared/pony/code/ regex \b(${capabilities})\b(?!')(!|\\^)? 1:attribute 2:attribute
|
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
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
2024-01-11 21:43:27 +01:00
|
|
|
define-command -hidden pony-insert-on-new-line %<
|
|
|
|
evaluate-commands -no-hooks -draft -itersel %<
|
2021-04-17 10:17:01 +02:00
|
|
|
# copy // comments prefix and following white spaces
|
2024-01-11 21:43:27 +01:00
|
|
|
try %{ execute-keys -draft k x s ^\h*\K//\h* <ret> y jgi P }
|
|
|
|
|
|
|
|
# wisely add `end` keyword
|
|
|
|
evaluate-commands -save-regs x %<
|
|
|
|
try %{ execute-keys -draft k x s ^ \h + <ret> \" x y } catch %{ reg x '' }
|
|
|
|
try %<
|
|
|
|
evaluate-commands -draft %<
|
|
|
|
# Check if previous line opens a block
|
|
|
|
execute-keys -draft kx <a-k>^<c-r>x(try|match|recover|repeat|object|.+\bdo$|.+\bthen$)[^0-9A-Za-z_']<ret>
|
|
|
|
# Check that we didn't put an end on the previous line that closes the block
|
|
|
|
execute-keys -draft kx <a-K> \bend$<ret>
|
|
|
|
# Check that we do not already have an end for this indent level which is first set via `pony-indent-on-new-line` hook
|
|
|
|
execute-keys -draft }i J x <a-K> ^<c-r>x(end|else|elseif|until)[^0-9A-Za-z_']<ret>
|
|
|
|
>
|
|
|
|
execute-keys -draft o<c-r>xend<esc> # insert a new line with containing end
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
|
|
|
>
|
2021-04-17 10:17:01 +02:00
|
|
|
|
2017-11-03 08:34:41 +01:00
|
|
|
define-command -hidden pony-indent-on-new-line %{
|
2024-01-11 21:43:27 +01:00
|
|
|
evaluate-commands -no-hooks -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 }
|
2024-01-11 21:43:27 +01:00
|
|
|
# indent after line ending with: =>, do, try, then, else, =; or
|
|
|
|
# starting with: actor, class, struct, trait, interface, if, elseif, recover, repeat
|
|
|
|
# excluding: primitive, type -- because they are often written in a single line
|
|
|
|
try %{ execute-keys -draft , k x <a-k> (\b(?:do|try|then|else|recover|repeat)|=>|=)$ | ^\h*(actor|class|struct|trait|interface|object)\b <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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-11 21:43:27 +01:00
|
|
|
§
|