X-Git-Url: https://git.donarmstrong.com/?p=dsa-puppet.git;a=blobdiff_plain;f=tools%2Fvim%2Findent%2Fpuppet.vim;fp=tools%2Fvim%2Findent%2Fpuppet.vim;h=689e06879d6d0ee7cd1e67b982f64ae8eaf80a07;hp=0000000000000000000000000000000000000000;hb=66b30d19cf524bbae55a178445fbb6079ba07765;hpb=6710ef26e1c124e536aef0cecd742fe27586ea63 diff --git a/tools/vim/indent/puppet.vim b/tools/vim/indent/puppet.vim new file mode 100644 index 00000000..689e0687 --- /dev/null +++ b/tools/vim/indent/puppet.vim @@ -0,0 +1,76 @@ +" Vim indent file +" Language: Puppet +" Maintainer: Todd Zullinger +" Last Change: 2009 Aug 19 +" 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) + + 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 + + " Match } }, }; ] ]: ) + if line =~ '^\s*\(}\(,\|;\)\?$\|]:\?$\|)\)' + let ind = indent(s:OpenBrace(v:lnum)) + endif + + return ind +endfunction