commit 57e55a2e5a38d482f3ffe906e7e64bdcd960480e Author: Nulo Date: Fri Jul 9 01:51:32 2021 +0000 Initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0661da1 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# zig.kak + +Useful tools for developing [Zig](https://ziglang.org) on [Kakoune](https://kakoune.org). Note that Kakoune already includes Zig syntax highlighting by default. + +Inspired by `make.kak` and `grep.kak`. + +## Commands + +### `zig-run [arguments]`: wrapper for `zig build run` + +> All the optional arguments are forwarded to zig build run. + +Runs `zig build run` and opens the result in a buffer with basic syntax highlighting for errors, also allows going to the position of the errors by pressing Return. + +### `zig-auto-run `: automatically run zig-run on save + +Add this to your kakrc to apply this when opening any Zig file: + +```kak +hook global WinSetOption filetype=zig %{ zig-auto-run buffer } +``` + +### `new-tools`: open a new client for tools (make.kak, grep.kak, zig.kak) to use for output + +Also sets the current client to be the one to go back to when jumping to an error. + +## Also useful + +Set the formatter for Zig files to `zig fmt`: + +```kak +hook global WinSetOption filetype=zig %{ + set-option buffer formatcmd 'zig fmt --stdin' + # Optionally format every time we save + #hook buffer BufWritePre .* format-buffer +} +``` diff --git a/rc/zig.kak b/rc/zig.kak new file mode 100644 index 0000000..149bae6 --- /dev/null +++ b/rc/zig.kak @@ -0,0 +1,62 @@ +define-command -params .. \ + -docstring %{ + zig-run []: wrapper for `zig build run` + All the optional arguments are forwarded to zig build run + } zig-run %{ evaluate-commands %sh{ + output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-zig.XXXXXXXX)/fifo + mkfifo ${output} + ( eval zig build run "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null + + printf %s\\n "evaluate-commands -try-client '$kak_opt_toolsclient' %{ + edit! -fifo ${output} -scroll *zig* + set-option buffer filetype zig-build + hook -always -once buffer BufCloseFifo .* %{ nop %sh{ rm -r $(dirname ${output}) } } + try %{ focus } + }" +}} + +define-command -params 1 \ + -docstring %{ + zig-auto-run : automatically run zig-run on save + } zig-auto-run %{ + hook %arg{1} BufWritePost .* %{ zig-run } +} + + +hook -group zig-build-highlight global WinSetOption filetype=zig-build %{ + add-highlighter window/zig-build group + add-highlighter window/zig-build/ regex '(error:)|(note:)' 1:Error 2:Information + add-highlighter window/zig-build/ regex '((?:\w|/|\.)+?):([0-9]+):([0-9]+): (?:.*?)' 1:variable 2:value 3:value + + hook buffer -group zig-hooks NormalKey zig-jump + hook -once -always window WinSetOption filetype=.* %{ + remove-hooks buffer zig-hooks + remove-highlighter window/zig-build + } +} + +define-command -hidden zig-open-error -params 4 %{ + evaluate-commands -try-client %opt{jumpclient} %{ + edit -existing "%arg{1}" %arg{2} %arg{3} + echo -markup "{Information}{\}%arg{4}" + try %{ focus } + } +} + +define-command -hidden zig-jump %{ + evaluate-commands %{ + execute-keys gl '((?:\w|/|\.)+):([0-9]+):([0-9]+): (.+?)' + execute-keys s '((?:\w|/|\.)+):([0-9]+):([0-9]+): (.+?)$' ; + zig-open-error "%reg{1}" "%reg{2}" "%reg{3}" "%reg{4}" + } +} + +define-command \ + -docstring %{ + new-tools: open a new client for tools (make.kak, grep.kak, zig.kak) to use for output + Also sets the current client to be the one to go back to when jumping to an error + } new-tools %{ + new rename-client tools + set-option global toolsclient tools + set-option global jumpclient %val{client} +}