2015-07-18 17:05:45 -04:00
|
|
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'puppet') == -1
|
|
|
|
|
2013-09-12 11:36:44 -04:00
|
|
|
" Vim indent file
|
2014-04-14 19:26:34 -04:00
|
|
|
" Language: Puppet
|
|
|
|
" Maintainer: Todd Zullinger <tmz@pobox.com>
|
|
|
|
" Last Change: 2009 Aug 19
|
2013-09-12 11:36:44 -04:00
|
|
|
" vim: set sw=4 sts=4:
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
" Check if a line is part of an include 'block', e.g.:
|
|
|
|
" include foo,
|
|
|
|
" bar,
|
|
|
|
" baz
|
|
|
|
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)
|
|
|
|
|
2016-05-02 04:48:28 -04:00
|
|
|
if pline =~ '\({\|\[\|(\|:\)\s*\(#.*\)\?$'
|
2013-09-12 11:36:44 -04:00
|
|
|
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
|
|
|
|
|
2014-04-14 19:26:34 -04:00
|
|
|
" Match } }, }; ] ]: ], ]; )
|
|
|
|
if line =~ '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)'
|
2013-09-12 11:36:44 -04:00
|
|
|
let ind = indent(s:OpenBrace(v:lnum))
|
|
|
|
endif
|
|
|
|
|
2014-04-14 19:26:34 -04:00
|
|
|
" Don't actually shift over for } else {
|
|
|
|
if line =~ '^\s*}\s*els\(e\|if\).*{\s*$'
|
|
|
|
let ind -= &sw
|
|
|
|
endif
|
2014-08-12 17:45:36 -04:00
|
|
|
|
|
|
|
" Don't indent resources that are one after another with a ->(ordering arrow)
|
|
|
|
" file {'somefile':
|
|
|
|
" ...
|
|
|
|
" } ->
|
|
|
|
"
|
|
|
|
" package { 'mycoolpackage':
|
|
|
|
" ...
|
|
|
|
" }
|
|
|
|
if line =~ '->$'
|
|
|
|
let ind -= &sw
|
|
|
|
endif
|
|
|
|
|
2014-04-14 19:26:34 -04:00
|
|
|
|
2013-09-12 11:36:44 -04:00
|
|
|
return ind
|
|
|
|
endfunction
|
2015-07-18 17:05:45 -04:00
|
|
|
|
|
|
|
endif
|