|
| 1 | +## |
| 2 | +## v.kak by Conscat |
| 3 | +## |
| 4 | + |
| 5 | +# https://vlang.io |
| 6 | +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 7 | + |
| 8 | +# Detection |
| 9 | +# ‾‾‾‾‾‾‾‾‾ |
| 10 | + |
| 11 | +hook global BufCreate .+\.(v|vsh) %{ |
| 12 | + set-option buffer filetype v |
| 13 | +} |
| 14 | + |
| 15 | +# Initialization |
| 16 | +# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ |
| 17 | + |
| 18 | +hook global WinSetOption filetype=v %{ |
| 19 | + require-module v |
| 20 | + add-highlighter window/v ref v |
| 21 | +} |
| 22 | + |
| 23 | +hook global WinSetOption filetype=(?!v).* %{ |
| 24 | + remove-highlighter window/v |
| 25 | +} |
| 26 | + |
| 27 | +hook global BufSetOption filetype=v %{ |
| 28 | + set-option buffer comment_line '//' |
| 29 | +} |
| 30 | + |
| 31 | +provide-module v %§ |
| 32 | + |
| 33 | +# Highlighters |
| 34 | +# ‾‾‾‾‾‾‾‾‾‾‾‾ |
| 35 | + |
| 36 | +add-highlighter shared/v regions |
| 37 | +add-highlighter shared/v/code default-region group |
| 38 | + |
| 39 | +add-highlighter shared/v/back_string region '`' '`' fill string |
| 40 | +add-highlighter shared/v/double_string region '"' (?<!\\)(\\\\)*" fill string |
| 41 | +add-highlighter shared/v/single_string region "'" (?<!\\)(\\\\)*' fill string |
| 42 | +add-highlighter shared/v/comment region -recurse /\* /\* \*/ fill comment |
| 43 | +add-highlighter shared/v/comment_line region '//' $ fill comment |
| 44 | + |
| 45 | +# TODO: Make attributes only highlight inside [] |
| 46 | +add-highlighter shared/v/code/ regex (\b(if|as|asm|assert|atomic|break|const|continue|else|embed|enum|fn|for|go|import|in|interface|is|lock|match|module|mut|or|pub|return|rlock|select|shared|sizeof|static|struct|type|typeof|union|__offsetof|free|unsafe|strlen|strncmp|malloc|goto|defer)\b|\$(if|else|for)|\[(deprecated|inline|heap|manualfree|live|direct_array_access|typedef|windows_stdcall|console|json:|raw)([^\]|(^\n)]*)\]) 0:keyword |
| 47 | + |
| 48 | +# |\[(deprecated|inline|heap|manualfree|live|direct_array_access|typedef|windows_stdcall|console|json:|raw)([^\])\] |
| 49 | + |
| 50 | +add-highlighter shared/v/code/ regex %{-?([0-9]*\.(?!0[xX]))?\b([0-9_]+|0[xX][0-9a-fA-F]+)\.?([eE][+-]?[0-9]+)?\.*|none|true|false\b} 0:value |
| 51 | +add-highlighter shared/v/code/ regex \b(chan|err|i8|u8|byte|i16|u16|int|u32|i64|u64|f32|f64|ptr|voidptr|r|size_t|map|rune|string)\b 0:type |
| 52 | + |
| 53 | +# TODO: Put os funcs in .vsh ref'd highlighter. |
| 54 | +add-highlighter shared/v/code/ regex \b(print|println|eprint|eprintln|exit|panic|print_backtrace|dump|rmdir_all|mkdir|exec|ls|mv)\b 0:builtin |
| 55 | + |
| 56 | +# TODO: asm funcs |
| 57 | +add-highlighter shared/v/code/ regex (<|>|=|\+|-|\*|/|%|~|&|\|||\^|!|\?|:=) 0:operator |
| 58 | + |
| 59 | +§ |
0 commit comments