robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
a412a4a846
master
1" Vim filetype indent file 2" Language: Zig 3" Upstream: https://codeberg.org/ziglang/zig.vim 4 5" Only load this indent file when no other was loaded. 6if exists ( "b:did_indent" ) 7finish 8endif 9let b: did_indent = 1 10 11if ( ! has ( "cindent" ) || ! has ( "eval" )) 12finish 13endif 14 15setlocal cindent 16 17" L0 -> 0 indent for jump labels (i.e. case statement in c). 18" j1 -> indenting for "javascript object declarations" 19" J1 -> see j1 20" w1 -> starting a new line with `(` at the same indent as `(` 21" m1 -> if `)` starts a line, match its indent with the first char of its 22" matching `(` line 23" (s -> use one indent, when starting a new line after a trailing `(` 24setlocal cinoptions = L0,m1,(s,j1,J1,l1 25 26" cinkeys: controls what keys trigger indent formatting 27" 0{ -> { 28" 0} -> } 29" 0) -> ) 30" 0] -> ] 31" !^F -> make CTRL-F (^F) reindent the current line when typed 32" o -> when <CR> or `o` is used 33" O -> when the `O` command is used 34setlocal cinkeys = 0{,0},0),0],!^F,o,O 35 36setlocal indentexpr = GetZigIndent (v:lnum) 37 38let b: undo_indent = "setlocal cindent< cinkeys< cinoptions< indentexpr<" 39 40function ! GetZigIndent ( lnum ) 41let curretLineNum = a: lnum 42let currentLine = getline ( a: lnum ) 43 44" cindent doesn't handle multi-line strings properly, so force no indent 45if currentLine =~ '^\s*\\\\.*' 46return -1 47endif 48 49let prevLineNum = prevnonblank ( a: lnum - 1 ) 50let prevLine = getline ( prevLineNum ) 51 52" for lines that look like 53" }, 54" }; 55" try treating them the same as a } 56if prevLine =~ '\v^\s*},$' 57if currentLine =~ '\v^\s*};$' || currentLine =~ '\v^\s*}$' 58return indent ( prevLineNum ) - 4 59endif 60return indent ( prevLineNum - 1 ) - 4 61endif 62if currentLine =~ '\v^\s*},$' 63return indent ( prevLineNum ) - 4 64endif 65if currentLine =~ '\v^\s*};$' 66return indent ( prevLineNum ) - 4 67endif 68 69 70" cindent doesn't handle this case correctly: 71" switch (1): { 72" 1 => true, 73" ~ 74" ^---- indents to here 75if prevLine =~ '.*=>.*,$' && currentLine !~ '.*}$' 76return indent ( prevLineNum ) 77endif 78 79return cindent ( a: lnum ) 80endfunction