]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/indent/puppet.vim
Replace deoplete with coc
[rbdr/dotfiles] / vim / indent / puppet.vim
... / ...
CommitLineData
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
7if exists("b:did_indent")
8 finish
9endif
10let b:did_indent = 1
11
12setlocal autoindent smartindent
13setlocal indentexpr=GetPuppetIndent()
14setlocal indentkeys+=0],0)
15
16if exists("*GetPuppetIndent")
17 finish
18endif
19
20" Check if a line is part of an include 'block', e.g.:
21" include foo,
22" bar,
23" baz
24function! 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
37endfunction
38
39function! s:OpenBrace(lnum)
40 call cursor(a:lnum, 1)
41 return searchpair('{\|\[\|(', '', '}\|\]\|)', 'nbW')
42endfunction
43
44function! 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
76endfunction