comparison .vim/indent/puppet.vim @ 109:07395fbde025

Adding puppet plugin: * Version cd0c2ed92ba1 from hg clone git+https://github.com/puppetlabs/puppet-syntax-vim.git * Added line to vimrc to load plugin properly
author Steve Huston <huston@astro.princeton.edu>
date Sat, 26 Apr 2014 17:57:50 -0400
parents
children
comparison
equal deleted inserted replaced
108:7da995f48c91 109:07395fbde025
1 " Vim indent file
2 " Language: Puppet
3 " Maintainer: Todd Zullinger <tmz@pobox.com>
4 " Last Change: 2009 Aug 19
5 " vim: set sw=4 sts=4:
6
7 if exists("b:did_indent")
8 finish
9 endif
10 let b:did_indent = 1
11
12 setlocal autoindent smartindent
13 setlocal indentexpr=GetPuppetIndent()
14 setlocal indentkeys+=0],0)
15
16 if exists("*GetPuppetIndent")
17 finish
18 endif
19
20 " Check if a line is part of an include 'block', e.g.:
21 " include foo,
22 " bar,
23 " baz
24 function! s:PartOfInclude(lnum)
25 let lnum = a:lnum
26 while lnum
27 let lnum = lnum - 1
28 let line = getline(lnum)
29 if line !~ ',$'
30 break
31 endif
32 if line =~ '^\s*include\s\+[^,]\+,$'
33 return 1
34 endif
35 endwhile
36 return 0
37 endfunction
38
39 function! s:OpenBrace(lnum)
40 call cursor(a:lnum, 1)
41 return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW')
42 endfunction
43
44 function! GetPuppetIndent()
45 let pnum = prevnonblank(v:lnum - 1)
46 if pnum == 0
47 return 0
48 endif
49
50 let line = getline(v:lnum)
51 let pline = getline(pnum)
52 let ind = indent(pnum)
53
54 if pline =~ '^\s*#'
55 return ind
56 endif
57
58 if pline =~ '\({\|\[\|(\|:\)$'
59 let ind += &sw
60 elseif pline =~ ';$' && pline !~ '[^:]\+:.*[=+]>.*'
61 let ind -= &sw
62 elseif pline =~ '^\s*include\s\+.*,$'
63 let ind += &sw
64 endif
65
66 if pline !~ ',$' && s:PartOfInclude(pnum)
67 let ind -= &sw
68 endif
69
70 " Match } }, }; ] ]: )
71 if line =~ '^\s*\(}\(,\|;\)\?$\|]:\?$\|)\)'
72 let ind = indent(s:OpenBrace(v:lnum))
73 endif
74
75 return ind
76 endfunction