Initial commit
This commit is contained in:
commit
57e55a2e5a
2 changed files with 99 additions and 0 deletions
37
README.md
Normal file
37
README.md
Normal file
|
@ -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 <scope>`: 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
|
||||||
|
}
|
||||||
|
```
|
62
rc/zig.kak
Normal file
62
rc/zig.kak
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
define-command -params .. \
|
||||||
|
-docstring %{
|
||||||
|
zig-run [<arguments>]: 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 <scope>: 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 <ret> 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<a-?> '((?:\w|/|\.)+):([0-9]+):([0-9]+): (.+?)' <ret>
|
||||||
|
execute-keys s '((?:\w|/|\.)+):([0-9]+):([0-9]+): (.+?)$' <ret>;
|
||||||
|
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}
|
||||||
|
}
|
Loading…
Reference in a new issue