# zig syntax highlighting for kakoune (https://ziglang.org) # # based off of https://github.com/ziglang/zig.vim/blob/master/syntax/zig.vim # as well as https://ziglang.org/documentation/master/#Grammar # Detection # ‾‾‾‾‾‾‾‾‾ hook global BufCreate .*[.]zig %{ set-option buffer filetype zig } # Initialization # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾ hook global WinSetOption filetype=zig %< require-module zig hook window ModeChange pop:insert:.* -group zig-trim-indent zig-trim-indent hook window InsertChar \n -group zig-indent zig-indent-on-new-line hook window InsertChar \} -group zig-indent zig-indent-on-closing hook -once -always window WinSetOption filetype=.* %< remove-hooks window zig-.+ > > hook -group zig-highlight global WinSetOption filetype=zig %{ require-module zig add-highlighter window/zig ref zig hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/zig } } provide-module zig %§ # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ add-highlighter shared/zig regions add-highlighter shared/zig/code default-region group add-highlighter shared/zig/doc_comment region '///(?=[^/])' '$' fill documentation add-highlighter shared/zig/comment region '//' '$' fill comment # strings and characters add-highlighter shared/zig/string region '"' (?|&|\||\^|~|\?|!)' 0:operator # builtin functions add-highlighter shared/zig/code/ regex "@(?:addWithOverflow|alignCast|alignOf|as|asyncCall|atomicLoad|atomicRmw|atomicStore|bitCast|bitOffsetOf|boolToInt|bitSizeOf|breakpoint|mulAdd|byteSwap|bitReverse|byteOffsetOf|call|cDefine|cImport|cInclude|clz|cmpxchgStrong|cmpxchgWeak|compileError|compileLog|ctz|cUndef|divExact|divFloor|divTrunc|embedFile|enumToInt|errorName|errorReturnTrace|errorToInt|errSetCast|export|fence|field|fieldParentPtr|floatCast|floatToInt|frame|Frame|frameAddress|frameSize|hasDecl|hasField|import|intCast|intToEnum|intToError|intToFloat|intToPtr|memcpy|memset|wasmMemorySize|wasmMemoryGrow|mod|mulWithOverflow|panic|popCount|ptrCast|ptrToInt|rem|returnAddress|setAlignStack|setCold|setEvalBranchQuota|setFloatMode|setRuntimeSafety|shlExact|shlWithOverflow|shrExact|shuffle|sizeOf|splat|reduce|src|sqrt|sin|cos|exp|exp2|log|log2|log10|fabs|floor|ceil|trunc|round|subWithOverflow|tagName|TagType|This|truncate|Type|typeInfo|typeName|TypeOf|unionInit)\b" 0:function # Commands # ‾‾‾‾‾‾‾‾ define-command -hidden zig-trim-indent %{ # delete trailing whitespace try %{ execute-keys -draft -itersel s \h+$ d } } define-command -hidden zig-indent-on-new-line %< evaluate-commands -draft -itersel %< try %< # copy // or /// comments prefix and following whitespace execute-keys -draft k s ^\h*\K///?\h* y gh j P # preserve indent level try %< execute-keys -draft K > > catch %< # preserve indent level try %< execute-keys -draft K > # indent after lines ending in { try %< execute-keys -draft k \{\h*$ j > # deindent closing } when after cursor try %< execute-keys -draft ^\h*\} gh / \} m 1 > > # filter previous line try %< execute-keys -draft k : zig-trim-indent > > > define-command -hidden zig-indent-on-closing %< # align lone } to indent level of opening line try %< execute-keys -draft -itersel ^\h*\}$ h m 1 > > §