Last active
February 14, 2022 11:50
-
-
Save lboklin/04274afa065182f188b02b8bb51595e2 to your computer and use it in GitHub Desktop.
Kakoune HVM filetype
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/Kindelia/HVM | |
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ | |
# Detection | |
# ‾‾‾‾‾‾‾‾‾ | |
hook global BufCreate .*[.](hvm) %{ | |
set-option buffer filetype hvm | |
} | |
# Initialization | |
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ | |
hook global WinSetOption filetype=hvm %{ | |
require-module hvm | |
set-option buffer comment_line '//' | |
hook window ModeChange pop:insert:.* -group hvm-trim-indent hvm-trim-indent | |
hook window InsertChar \n -group hvm-insert hvm-insert-on-new-line | |
hook window InsertChar \n -group hvm-indent hvm-indent-on-new-line | |
hook -once -always window WinSetOption filetype=.* %{ remove-hooks window hvm-.+ } | |
} | |
hook -group hvm-highlight global WinSetOption filetype=hvm %{ | |
add-highlighter window/hvm ref hvm | |
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/hvm } | |
} | |
provide-module hvm %[ | |
# Highlighters | |
# ‾‾‾‾‾‾‾‾‾‾‾‾ | |
add-highlighter shared/hvm regions | |
add-highlighter shared/hvm/code default-region group | |
add-highlighter shared/hvm/string region %{"} [^"]*" fill string | |
add-highlighter shared/hvm/line_comment region (//) $ fill comment | |
add-highlighter shared/hvm/code/ regex \b[A-Z]\w*\b 0:type | |
add-highlighter shared/hvm/code/ regex ^[(]?\K[A-Z]\w*\b 0:function | |
add-highlighter shared/hvm/code/ regex (\b|λ)[a-z_]\w*\b 0:variable | |
add-highlighter shared/hvm/code/ regex \b[0-9]+ 0:value | |
add-highlighter shared/hvm/code/ regex [(]\K[-+*/%&\\|^<>!=]+(\h|$) 0:operator | |
add-highlighter shared/hvm/code/ regex \blet\b|[@λ](?=[a-z_])|\h=(\h|$) 0:keyword | |
add-highlighter shared/hvm/code/ regex \bdup\b|\h(<-)(\h|$)|[{}] 0:meta | |
# Commands | |
# ‾‾‾‾‾‾‾‾ | |
define-command -hidden hvm-trim-indent %{ | |
# remove trailing white spaces | |
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d } | |
} | |
define-command -hidden hvm-indent-after " | |
execute-keys -draft <semicolon> k x <a-k> ^.*[=(]$ <ret> j <a-gt> | |
" | |
define-command -hidden hvm-insert-on-new-line %{ | |
evaluate-commands -draft -itersel %{ | |
# copy // comments prefix and following white spaces | |
try %{ execute-keys -draft k <a-x> s ^\h*\K//\h* <ret> y gh j P } | |
} | |
} | |
define-command -hidden hvm-indent-on-new-line %{ | |
evaluate-commands -draft -itersel %{ | |
# preserve previous line indent | |
try %{ execute-keys -draft <semicolon> K <a-&> } | |
# filter previous line | |
try %{ execute-keys -draft k : hvm-trim-indent <ret> } | |
# indent after lines beginning with condition or ending with expression or =( | |
try %{ hvm-indent-after } | |
} | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment