Skip to content
Browse files

Add indent support

  • Loading branch information...
1 parent 5635e50 commit b0dbf8e43a12ec52efd541b594a0a6c4b41f5f40 @rodjek committed Jul 24, 2011
Showing with 87 additions and 5 deletions.
  1. +76 −0 indent/puppet.vim
  2. +11 −5 syntax/puppet.vim
View
76 indent/puppet.vim
@@ -0,0 +1,76 @@
+" Vim indent file
+" Language: Puppet
+" Maintainer: Todd Zullinger <tmz@pobox.com>
+" 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
View
16 syntax/puppet.vim
@@ -17,13 +17,15 @@ elseif exists("b:current_syntax")
endif
syn region puppetDefine start="^\s*\(class\|define\|site\|node\)\s+" end="{" contains=puppetDefType,puppetDefName,puppetDefArguments
-syn keyword puppetDefType class define site node inherits contained
-syn keyword puppetInherits inherits contained
-syn region puppetDefArguments start="(" end=")" contains=puppetArgument
+syn match puppetDefType "\(class\|define\|site\|node\|inherits\)" contained
+syn match puppetInherits "inherits" contained
+syn region puppetDefArguments start="(" end=")\s*" contains=puppetArgument
syn match puppetArgument "\w\+" contained
-syn match puppetDefName "\(\w\|\:\)\+" contained
+syn match puppetDefName "\(\w\|\:\)\+\s*" contained
syn match puppetInstance "\(\w\|\:\)\+\s*{" contains=puppetTypeBrace,puppetTypeName,puppetTypeDefault
+syn match puppetExisting "[A-Z\:]\(\w\|\:\)*\[" contains=puppetTypeDefault,puppetTypeBrack
+syn match puppetTypeBrack "\[" contained
syn match puppetTypeBrace "{" contained
syn match puppetTypeName "[a-z]\w*" contained
syn match puppetTypeDefault "[A-Z]\w*" contained
@@ -37,6 +39,8 @@ syn match puppetParen "("
syn match puppetParen ")"
syn match puppetBrace "{"
syn match puppetBrace "}"
+syn match puppetBrack "\["
+syn match puppetBrack "\]"
syn region puppetString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable
syn region puppetString start=+'+ skip=+\\\\\|\\"+ end=+'+
@@ -69,13 +73,15 @@ if version >= 508 || !exists("did_puppet_syn_inits")
HiLink puppetComment Comment
HiLink puppetString String
HiLink puppetTodo Todo
+ HiLink puppetBrack Delimiter
+ HiLink puppetTypeBrack Delimiter
HiLink puppetBrace Delimiter
HiLink puppetTypeBrace Delimiter
HiLink puppetParen Delimiter
HiLink puppetDelimiter Delimiter
HiLink puppetControl Statement
HiLink puppetDefType Define
- HiLink puppetDefName Type
+ HiLink puppetDefName Identifier
HiLink puppetTypeName Statement
HiLink puppetTypeDefault Type
HiLink puppetParamName Identifier

0 comments on commit b0dbf8e

Please sign in to comment.
Something went wrong with that request. Please try again.