2017-11-29 17:15:00 +01:00
|
|
|
# https://nim-lang.org/
|
|
|
|
#
|
|
|
|
|
|
|
|
# Detection
|
|
|
|
# ‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2017-12-09 21:55:57 +01:00
|
|
|
hook global BufCreate .*\.nim(s|ble)? %{
|
2017-11-29 17:15:00 +01:00
|
|
|
set-option buffer filetype nim
|
|
|
|
}
|
|
|
|
|
|
|
|
# Highlighters
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/nim regions
|
|
|
|
add-highlighter shared/nim/code default-region group
|
2018-09-28 11:41:10 +02:00
|
|
|
add-highlighter shared/nim/single_string region "'" (?<!\\)(\\\\)*' fill string
|
2018-07-02 12:59:12 +02:00
|
|
|
add-highlighter shared/nim/double_string region '"' (?<!\\)(\\\\)*" fill string
|
|
|
|
add-highlighter shared/nim/triple_string region '"""' '"""' fill string
|
|
|
|
add-highlighter shared/nim/comment region '#?#\[' '\]##?' fill comment
|
2017-11-29 17:15:00 +01:00
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/nim/code/ regex \b(0[xXocCbB])?[\d_]+('[iIuUfFdD](8|16|32|64|128))?\b 0:value
|
|
|
|
add-highlighter shared/nim/code/ regex \b\d+\.\d+\b 0:value
|
|
|
|
add-highlighter shared/nim/code/ regex %{'[^'\n]'} 0:string
|
2017-11-29 17:15:00 +01:00
|
|
|
|
2018-05-06 23:29:52 +02:00
|
|
|
evaluate-commands %sh{
|
2017-11-29 17:15:00 +01:00
|
|
|
# Grammar
|
|
|
|
keywords="addr|and|as|asm|atomic|bind|block|break|case|cast|concept|const"
|
|
|
|
keywords="${keywords}|continue|converter|defer|discard|distinct|div|do|elif"
|
|
|
|
keywords="${keywords}|else|end|enum|except|export|finally|for|from|func"
|
|
|
|
keywords="${keywords}|generic|if|import|in|include|interface|is|isnot"
|
|
|
|
keywords="${keywords}|iterator|let|macro|method|mixin|mod|nil|not|notin"
|
|
|
|
keywords="${keywords}|of|or|out|proc|ptr|raise|ref|return|shl|shr"
|
|
|
|
keywords="${keywords}|static|template|try|type|using|var|when|while"
|
|
|
|
keywords="${keywords}|with|without|xor|yield"
|
|
|
|
types="int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float"
|
|
|
|
types="${types}|float32|float64|bool|char|object|seq|array|cstring|string"
|
|
|
|
types="${types}|tuple|varargs"
|
|
|
|
values="false|true"
|
|
|
|
|
|
|
|
# Add the language's grammar to the static completion list
|
|
|
|
printf %s\\n "hook global WinSetOption filetype=nim %{
|
2018-06-17 05:30:40 +02:00
|
|
|
set-option window static_words ${keywords} ${types} ${values}
|
|
|
|
}" | tr '|' ' '
|
2017-11-29 17:15:00 +01:00
|
|
|
|
|
|
|
# Highlight keywords
|
|
|
|
printf %s "
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/nim/code/ regex \b(${keywords})\b 0:keyword
|
|
|
|
add-highlighter shared/nim/code/ regex \b(${types})\b 0:type
|
|
|
|
add-highlighter shared/nim/code/ regex \b(${values})\b 0:value
|
2017-11-29 17:15:00 +01:00
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
add-highlighter shared/nim/code/ regex '#[^\n]+' 0:comment
|
2017-11-29 17:15:00 +01:00
|
|
|
|
2017-12-09 21:55:57 +01:00
|
|
|
# Commands
|
|
|
|
# ‾‾‾‾‾‾‾‾
|
|
|
|
|
|
|
|
def -hidden nim-indent-on-new-line %{
|
|
|
|
eval -draft -itersel %{
|
|
|
|
# copy '#' comment prefix and following white spaces
|
|
|
|
try %{ exec -draft k <a-x> s ^\h*#\h* <ret> y jgh P }
|
|
|
|
# preserve previous line indent
|
|
|
|
try %{ exec -draft \; K <a-&> }
|
|
|
|
# cleanup trailing whitespaces from previous line
|
|
|
|
try %{ exec -draft k <a-x> s \h+$ <ret> d }
|
|
|
|
# indent after line ending with const, let, var, ':' or '='
|
|
|
|
try %{ exec -draft <space> k x <a-k> (:|=|const|let|var)$ <ret> j <a-gt> }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-29 17:15:00 +01:00
|
|
|
# Initialization
|
|
|
|
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
|
|
|
|
|
2018-07-01 11:53:35 +02:00
|
|
|
hook -group nim-highlight global WinSetOption filetype=nim %{ add-highlighter window/nim ref nim }
|
2017-11-29 17:15:00 +01:00
|
|
|
|
2017-12-09 21:55:57 +01:00
|
|
|
hook global WinSetOption filetype=nim %{
|
|
|
|
hook window InsertChar \n -group nim-indent nim-indent-on-new-line
|
|
|
|
# cleanup trailing whitespaces on current line insert end
|
2018-01-21 00:35:05 +01:00
|
|
|
hook window ModeChange insert:.* -group nim-indent %{ try %{ exec -draft \; <a-x> s ^\h+$ <ret> d } }
|
2017-12-09 21:55:57 +01:00
|
|
|
}
|
|
|
|
|
2017-11-29 17:15:00 +01:00
|
|
|
hook -group nim-highlight global WinSetOption filetype=(?!nim).* %{ remove-highlighter window/nim }
|
2017-12-09 21:55:57 +01:00
|
|
|
|
|
|
|
hook global WinSetOption filetype=(?!nim).* %{
|
|
|
|
remove-hooks window nim-indent
|
|
|
|
}
|