milly/extra/inf.kak

50 lines
1.7 KiB
Plaintext

# Detection
hook global BufCreate .*\.(mil) %{
set-option buffer filetype inf
}
hook global WinSetOption filetype=inf %{
require-module inf
}
hook -group inf-highlighter global WinSetOption filetype=inf %{
add-highlighter window/inf ref inf
hook -once -always window WinSetOption filetype=.* %{
remove-highlighter window/inf
}
}
provide-module inf %§
# Highlighters & Completion
add-highlighter shared/inf regions
add-highlighter shared/inf/code default-region group
add-highlighter shared/inf/comment region (^|\h)\K# $ fill comment
add-highlighter shared/inf/double_string region -recurse %{(?<!")("")+(?!")} %{(^|\h)\K"} %{"(?!")} group
evaluate-commands %sh{
# Grammar
keywords="case let in match of def datatype alias typecheck"
types="int bool string list"
values="true false"
join() { sep=$2; eval set -- $1; IFS="$sep"; echo "$*"; }
# Add the language's grammar to the static completion list
printf %s\\n "declare-option str-list kak_static_words $(join "${keywords} ${attributes} ${types} ${values}" ' ')'"
# Highlight keywords (which are always surrounded by whitespace)
printf '%s\n' "add-highlighter shared/inf/code/keywords regex (?:\s|\A)\K($(join "${keywords}" '|'))(?:(?=\s)|\z) 0:keyword
add-highlighter shared/inf/code/types regex (?:\s|\A)\K($(join "${types}" '|'))(?:(?=\s)|\z) 0:type
add-highlighter shared/inf/code/values regex (?:\s|\A)\K($(join "${values}" '|'))(?:(?=\s)|\z) 0:value"
}
add-highlighter shared/inf/code/numbers regex \b\d+\b 0:value
add-highlighter shared/inf/double_string/fill fill string
add-highlighter shared/inf/double_string/escape regex '""' 0:default+b
§