Add indent rules
This commit is contained in:
parent
23b28df1b8
commit
3098557e25
|
@ -7,6 +7,14 @@ hook global BufCreate .*[.]zig %{
|
|||
set-option buffer filetype zig
|
||||
}
|
||||
|
||||
hook global WinSetOption filetype=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 %{
|
||||
add-highlighter window/zig ref zig
|
||||
hook -once -always window WinSetOption filetype=.* %{ remove-highlighter window/zig }
|
||||
|
@ -79,3 +87,29 @@ add-highlighter shared/zig/code/ regex "@(?:shlWithOverflow|shrExact|sizeOf|bitS
|
|||
add-highlighter shared/zig/code/ regex "@(?:truncate|typeId|typeInfo|typeName|TypeOf|atomicRmw|bytesToSlice|sliceToBytes)\b" 0:function
|
||||
add-highlighter shared/zig/code/ regex "@(?:intToError|errorToInt|intToEnum|enumToInt|setAlignStack|frame|Frame|frameSize|bitReverse|Vector)\b" 0:function
|
||||
add-highlighter shared/zig/code/ regex "@(?:sin|cos|exp|exp2|log|log2|log10|fabs|floor|ceil|trunc|round)\b" 0:function
|
||||
|
||||
define-command -hidden zig-trim-indent %{
|
||||
# delete trailing whitespace
|
||||
try %{ execute-keys -draft -itersel <a-x> s \h+$ <ret> d }
|
||||
}
|
||||
|
||||
define-command -hidden zig-indent-on-new-line %<
|
||||
evaluate-commands -draft -itersel %<
|
||||
# copy // or /// comments prefix and following white spaces
|
||||
try %<
|
||||
execute-keys -draft k <a-x> s ^\h*\K///?\h* <ret> y gh j P
|
||||
> catch %<
|
||||
# preserve indent level
|
||||
try %< execute-keys -draft <semicolon> K <a-&> >
|
||||
# indent after lines ending in {
|
||||
try %< execute-keys -draft k <a-x> <a-k> \{\h*$ <ret> j <a-gt> >
|
||||
>
|
||||
# filter previous line
|
||||
try %< execute-keys -draft k : zig-trim-indent <ret> >
|
||||
>
|
||||
>
|
||||
|
||||
define-command -hidden zig-indent-on-closing %<
|
||||
# align lone } to indent level of opening line
|
||||
try %< execute-keys -draft -itersel <a-h> <a-k> ^\h*\}$ <ret> h m <a-S> 1<a-&> >
|
||||
>
|
||||
|
|
Loading…
Reference in New Issue
Block a user