From f8d82dd24b7cf1f122c4de36c2cca05baf8d1e0e Mon Sep 17 00:00:00 2001 From: Noah Graff Date: Wed, 29 Jan 2020 21:06:56 -0500 Subject: [PATCH] back up zig.kak filetype file --- .config/kak/autoload/filetype/zig.kak | 97 +++++++++++++++++++++++++++ .config/kak/kakrc | 3 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 .config/kak/autoload/filetype/zig.kak diff --git a/.config/kak/autoload/filetype/zig.kak b/.config/kak/autoload/filetype/zig.kak new file mode 100644 index 0000000..ab81501 --- /dev/null +++ b/.config/kak/autoload/filetype/zig.kak @@ -0,0 +1,97 @@ +# Detection + +hook global BufCreate .*[.](zig) %{ + set-option buffer filetype zig +} + +# Highlighters + +add-highlighter shared/zig regions +add-highlighter shared/zig/code default-region group +add-highlighter shared/zig/string region c?" (?|<|%|>>)=? 0:operator +add-highlighter shared/zig/code/ regex -> 0:operator + +# Commands + +define-command -hidden zig-filter-around-selections %{ + # remove trailing whitspace + try %{ execute-keys -draft -itersel s\h+$ d } +} + +define-command -hidden zig-indent-on-new-line %[ + evaluate-commands -draft -itersel %[ + # copy comment prefix // + try %{ execute-keys -draft k s^\h*\K///?\h* y gh j P } + # preserve indent + try %{ execute-keys -draft ';' K } + # filter previous line + try %{ execute-keys -draft k :zig-filter-around-selections } + # indent after lines ending with { or ( + try %[ execute-keys -draft k [{(]\h*$ j ] + ] +] + +define-command -hidden zig-indent-on-closing-curly-brace %[ + evaluate-commands -draft -itersel %[ + # align to opening brace when the closing brace is the only thing on this line + try %[ execute-keys -draft ^\h+\}$ h m s\A|.\z 1 ] + ] +] + +# Initialization + +hook -group zig-highlight global WinSetOption filetype=zig %{ + add-highlighter window/zig ref zig + + hook -once -always window WinSetOption filetype=.* %{ + remove-highlighter window/zig + } +} + +hook global WinSetOption filetype=zig %[ + set-option buffer comment_line '//' + hook -group zig-hooks window ModeChange insert:.* zig-filter-around-selections + hook -group zig-indent window InsertChar \n zig-indent-on-new-line + hook -group zig-indent window InsertChar \} zig-indent-on-closing-curly-brace + + hook -once -always window WinSetOption filetype=.* %{ + remove-hooks window zig-.+ + } +] diff --git a/.config/kak/kakrc b/.config/kak/kakrc index 4c6d26e..1e4c208 100644 --- a/.config/kak/kakrc +++ b/.config/kak/kakrc @@ -59,7 +59,7 @@ define-command latex-preview %{ # |_| filetype-hook html|markdown|ocaml|gas|nim|latex %{ indent-spaces 2 } -filetype-hook zig|javascript|haskell|python|rust|kak|c|fish %{ indent-spaces 4 } +filetype-hook zig|javascript|haskell|python|rust|kak|c|fish|json %{ indent-spaces 4 } filetype-hook css %{ indent-tabs 4 } hook global WinCreate ^[^*]+$ %{ @@ -94,6 +94,7 @@ filetype-hook markdown %{ } + # __ __ _ # | \/ |__ _ _ __ _ __(_)_ _ __ _ ___ # | |\/| / _` | '_ \ '_ \ | ' \/ _` (_-< -- 2.34.2