12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- if exists("b:did_indent")
- finish
- endif
- let b:did_indent = 1
- setlocal autoindent smartindent
- setlocal indentexpr=GetPuppetIndent()
- setlocal indentkeys+=0],0)
- if exists("*GetPuppetIndent")
- finish
- endif
- function! s:PartOfInclude(lnum)
- let lnum = a:lnum
- while lnum
- let lnum = lnum - 1
- let line = getline(lnum)
- if line !~ ',$'
- break
- endif
- if line =~ '^\s*include\s\+[^,]\+,$'
- return 1
- endif
- endwhile
- return 0
- endfunction
- function! s:OpenBrace(lnum)
- call cursor(a:lnum, 1)
- return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW')
- endfunction
- function! GetPuppetIndent()
- let pnum = prevnonblank(v:lnum - 1)
- if pnum == 0
- return 0
- endif
- let line = getline(v:lnum)
- let pline = getline(pnum)
- let ind = indent(pnum)
- if pline =~ '^\s*#'
- return ind
- endif
- if pline =~ '\({\|\[\|(\|:\)$'
- let ind += &sw
- elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*'
- let ind -= &sw
- elseif pline =~ '^\s*include\s\+.*,$'
- let ind += &sw
- endif
- if pline !~ ',$' && s:PartOfInclude(pnum)
- let ind -= &sw
- endif
-
- if line =~ '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)'
- let ind = indent(s:OpenBrace(v:lnum))
- endif
-
- if line =~ '^\s*}\s*els\(e\|if\).*{\s*$'
- let ind -= &sw
- endif
-
-
-
-
-
-
-
-
-
- if line =~ '->$'
- let ind -= &sw
- endif
- return ind
- endfunction
|