Change puppet vendor, closes #24

This commit is contained in:
Adam Stankiewicz 2014-04-15 01:26:34 +02:00
parent 6c198a3ca9
commit b36260d015
6 changed files with 98 additions and 164 deletions

11
after/ftplugin/puppet.vim Normal file
View File

@ -0,0 +1,11 @@
inoremap <buffer> <silent> > ><Esc>:call <SID>puppetalign()<CR>A
function! s:puppetalign()
let p = '^\s*\w+\s*[=+]>.*$'
let lineContainsHashrocket = getline('.') =~# '^\s*\w+\s*[=+]>'
let hashrocketOnPrevLine = getline(line('.') - 1) =~# p
let hashrocketOnNextLine = getline(line('.') + 1) =~# p
if exists(':Tabularize') " && lineContainsHashrocket && (hashrocketOnPrevLine || hashrocketOnNextLine)
Tabularize /=>/l1
normal! 0
endif
endfunction

2
build
View File

@ -97,7 +97,7 @@ PACKS="
opencl:petRUShka/vim-opencl
perl:vim-perl/vim-perl
php:StanAngeloff/php.vim
puppet:ajf/puppet-vim
puppet:rodjek/vim-puppet
protobuf:uarun/vim-protobuf
python:mitsuhiko/vim-python-combined
r-lang:vim-scripts/R.vim

View File

@ -87,7 +87,7 @@ endif
au BufRead,BufNewFile /etc/nginx/*,/usr/local/nginx/*,*/nginx/vhosts.d/*,nginx.conf if &ft == '' | setfiletype nginx | endif
au BufRead,BufNewFile *.cl set filetype=opencl
autocmd BufNewFile,BufRead *.proto setfiletype proto
au BufRead,BufNewFile *.pp set filetype=puppet
au! BufRead,BufNewFile *.pp setfiletype puppet
function! s:setf(filetype) abort
if &filetype !=# a:filetype
let &filetype = a:filetype

View File

@ -1,137 +1,6 @@
" Vim filetype plugin
" Language: Puppet
" Maintainer: Todd Zullinger <tmz@pobox.com>
" Last Change: 2009 Aug 19
" vim: set sw=4 sts=4:
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
if !exists("no_plugin_maps") && !exists("no_puppet_maps")
if !hasmapto("<Plug>AlignRange")
map <buffer> <LocalLeader>= <Plug>AlignRange
endif
endif
noremap <buffer> <unique> <script> <Plug>AlignArrows :call <SID>AlignArrows()<CR>
noremap <buffer> <unique> <script> <Plug>AlignRange :call <SID>AlignRange()<CR>
iabbrev => =><C-R>=<SID>AlignArrows('=>')<CR>
iabbrev +> +><C-R>=<SID>AlignArrows('+>')<CR>
if exists('*s:AlignArrows')
finish
endif
let s:arrow_re = '[=+]>'
let s:selector_re = '[=+]>\s*\$.*\s*?\s*{\s*$'
" set keywordprg to 'pi' (alias for puppet describe)
" this lets K invoke pi for word under cursor
setlocal keywordprg=puppet\ describe
function! s:AlignArrows(op)
let cursor_pos = getpos('.')
let lnum = line('.')
let line = getline(lnum)
if line !~ s:arrow_re
return
endif
let pos = stridx(line, a:op)
let start = lnum
let end = lnum
let pnum = lnum - 1
while 1
let pline = getline(pnum)
if pline !~ s:arrow_re || pline =~ s:selector_re
break
endif
let start = pnum
let pnum -= 1
endwhile
let cnum = end
while 1
let cline = getline(cnum)
if cline !~ s:arrow_re ||
\ (indent(cnum) != indent(cnum+1) && getline(cnum+1) !~ '\s*}')
break
endif
let end = cnum
let cnum += 1
endwhile
call s:AlignSection(start, end)
let cursor_pos[2] = stridx(getline('.'), a:op) + strlen(a:op) + 1
call setpos('.', cursor_pos)
return ''
endfunction
function! s:AlignRange() range
call s:AlignSection(a:firstline, a:lastline)
endfunction
" AlignSection and AlignLine are from the vim wiki:
" http://vim.wikia.com/wiki/Regex-based_text_alignment
function! s:AlignSection(start, end)
let extra = 1
let sep = s:arrow_re
let maxpos = 0
let section = getline(a:start, a:end)
for line in section
let pos = match(line, ' *'.sep)
if maxpos < pos
let maxpos = pos
endif
endfor
call map(section, 's:AlignLine(v:val, sep, maxpos, extra)')
call setline(a:start, section)
endfunction
function! s:AlignLine(line, sep, maxpos, extra)
let m = matchlist(a:line, '\(.\{-}\) \{-}\('.a:sep.'.*\)')
if empty(m)
return a:line
endif
let spaces = repeat(' ', a:maxpos - strlen(m[1]) + a:extra)
return m[1] . spaces . m[2]
endfunction
" detect if we are in a module and set variables for classpath (autoloader),
" modulename, modulepath, and classname
" useful to use in templates
function! s:SetModuleVars()
" set these to any dirs you want to stop searching on
" useful to stop vim from spinning disk looking all over for init.pp
" probably only a macosx problem with /tmp since it's really /private/tmp
" but it's here if you find vim spinning on new files in certain places
if !exists("g:puppet_stop_dirs")
let g:puppet_stop_dirs = '/tmp;/private/tmp'
endif
" search path for init.pp
let b:search_path = './**'
let b:search_path = b:search_path . ';' . getcwd() . ';' . g:puppet_stop_dirs
" find what we assume to be our module dir
let b:initpp = findfile("init.pp", b:search_path) " find an init.pp up or down
let b:module_path = fnamemodify(b:initpp, ":p:h:h") " full path to module name
let b:module_name = fnamemodify(b:module_path, ":t") " just the module name
" sub out the full path to the module with the name and replace slashes with ::
let b:classpath = fnamemodify(expand("%:p:r"), ':s#' . b:module_path . '/manifests#' . b:module_name . '#'. ":gs?/?::?")
let b:classname = expand("%:t:r")
" if we don't start with a word we didn't replace the module_path
" probably b/c we couldn't find an init.pp / not a module
" so we assume that root of the filename is the class (sane for throwaway
" manifests
if b:classpath =~ '^::'
let b:classpath = b:classname
endif
endfunction
if exists("g:puppet_module_detect")
call s:SetModuleVars()
endif
setl ts=2
setl sts=2
setl sw=2
setl et
setl keywordprg=puppet\ describe\ --providers
setl iskeyword=-,:,@,48-57,_,192-255

View File

@ -1,7 +1,7 @@
" Vim indent file
" Language: Puppet
" Maintainer: Todd Zullinger <tmz@pobox.com>
" Last Change: 2009 Aug 19
" Language: Puppet
" Maintainer: Todd Zullinger <tmz@pobox.com>
" Last Change: 2009 Aug 19
" vim: set sw=4 sts=4:
if exists("b:did_indent")
@ -67,10 +67,15 @@ function! GetPuppetIndent()
let ind -= &sw
endif
" Match } }, }; ] ]: )
if line =~ '^\s*\(}\(,\|;\)\?$\|]:\?$\|)\)'
" Match } }, }; ] ]: ], ]; )
if line =~ '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)'
let ind = indent(s:OpenBrace(v:lnum))
endif
" Don't actually shift over for } else {
if line =~ '^\s*}\s*els\(e\|if\).*{\s*$'
let ind -= &sw
endif
return ind
endfunction

View File

@ -17,9 +17,9 @@ elseif exists("b:current_syntax")
endif
" match class/definition/node declarations
syn region puppetDefine start="^\s*\(class\|define\|node\)\s" end="{" contains=puppetDefType,puppetDefName,puppetDefArguments,puppetNodeRe
syn region puppetDefine start="^\s*\(class\|define\|node\)\s" end="{" contains=puppetDefType,puppetDefName,puppetDefArguments,puppetNodeRe,@NoSpell
syn keyword puppetDefType class define node inherits contained
syn region puppetDefArguments start="(" end=")" contained contains=puppetArgument,puppetString
syn region puppetDefArguments start="(" end=")" contained contains=puppetArgument,puppetString,puppetComment,puppetMultilineComment
syn match puppetArgument "\w\+" contained
syn match puppetArgument "\$\w\+" contained
syn match puppetArgument "'[^']+'" contained
@ -31,15 +31,24 @@ syn match puppetNodeRe "/.*/" contained
" match 'foo::bar' in 'class foo::bar { ...'
" match 'Foo::Bar' in 'Foo::Bar["..."]
"FIXME: "Foo-bar" doesn't get highlighted as expected, although "foo-bar" does.
syn match puppetInstance "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)*\s*{" contains=puppetTypeName,puppetTypeDefault
syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*[[{]" contains=puppetTypeName,puppetTypeDefault
syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*<\?<|" contains=puppetTypeName,puppetTypeDefault
syn match puppetInstance "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)*\s*{" contains=puppetTypeName,puppetTypeDefault,@NoSpell
syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*[[{]" contains=puppetTypeName,puppetTypeDefault,@NoSpell
syn match puppetInstance "[A-Z][a-z_-]\+\(::[A-Z][a-z_-]\+\)*\s*<\?<|" contains=puppetTypeName,puppetTypeDefault,@NoSpell
syn match puppetTypeName "[a-z]\w*" contained
syn match puppetTypeDefault "[A-Z]\w*" contained
" match 'foo' in 'foo => "bar"'
syn match puppetParam "\w\+\s*[=+]>" contains=puppetParamName
syn match puppetParamName "\w\+" contained
syn match puppetParam "\w\+\s*\(=\|+\)>" contains=puppetTypeRArrow,puppetParamName
syn match puppetParamRArrow "\(=\|+\)>" contained
syn match puppetParamName "\w\+" contained contains=@NoSpell
syn match puppetVariable "$\(\(\(::\)\?\w\+\)\+\|{\(\(::\)\?\w\+\)\+}\)"
syn match puppetParen "("
syn match puppetParen ")"
syn match puppetBrace "{"
syn match puppetBrace "}"
syn match puppetBrack "\["
syn match puppetBrack "\]"
syn match puppetBrack "<|"
syn match puppetBrack "|>"
" match 'present' in 'ensure => present'
" match '2755' in 'mode => 2755'
@ -57,25 +66,49 @@ syn region puppetFunction start="^\s*\(alert\|crit\|debug\|emerg\|err\|fai
" rvalues
syn region puppetFunction start="^\s*\(defined\|file\|fqdn_rand\|generate\|inline_template\|regsubst\|sha1\|shellquote\|split\|sprintf\|tagged\|template\|versioncmp\)\s*(" end=")" contained contains=puppetString
syn match puppetVariable "$[a-zA-Z0-9_:]\+"
syn match puppetVariable "${[a-zA-Z0-9_:]\+}"
syn match puppetVariable "$[a-zA-Z0-9_:]\+" contains=@NoSpell
syn match puppetVariable "${[a-zA-Z0-9_:]\+}" contains=@NoSpell
" match anything between simple/double quotes.
" don't match variables if preceded by a backslash.
syn region puppetString start=+'+ skip=+\\\\\|\\'+ end=+'+
syn region puppetString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=puppetVariable,puppetNotVariable
syn match puppetString "/[^/]*/"
syn match puppetNotVariable "\\$\w\+" contained
syn match puppetNotVariable "\\${\w\+}" contained
syn keyword puppetKeyword import inherits include
syn keyword puppetKeyword import inherits include require
syn keyword puppetControl case default if else elsif
syn keyword puppetSpecial true false undef
syn match puppetClass "[A-Za-z0-9_-]\+\(::[A-Za-z0-9_-]\+\)\+" contains=@NoSpell
" Match the Regular Expression type
" XXX: Puppet does not currently support a few features available in the
" full Ruby Regexp class, namely, interpolation, lookbehind and named
" sub-expressions. Matches for these features are included in the
" commented-out versions of puppetRegexParen and puppetRegexSubName,
" plus the supporting groups puppetRegexAngBrack and puppetRegexTick.
syn region puppetRegex start="/" skip="\\/" end="/" contains=puppetRegexParen,puppetRegexBrace,puppetRegexOrpuppetRegexBrack,puppetRegexComment
syn match puppetRegexParen "(\(?\([imx]\{0,4}:\|[=!]\)\)\?" contains=puppetRegexSpecChar,puppetRegexSubName contained
"syn match puppetRegexParen "(\(?\([imxo]\{0,4}:\|['<][[:alnum:]]\+[>']\|<?[=!]\)\)\?" contains=puppetRegexSpecChar,puppetRegexSubName contained
syn match puppetRegexParen ")" contained
syn match puppetRegexBrace "{" contained
syn match puppetRegexBrace "}" contained
syn match puppetRegexBrack "\[" contained
syn match puppetRegexBrack "\]" contained
"syn match puppetRegexAngBrack "<" contained
"syn match puppetRegexAngBrack ">" contained
"syn match puppetRegexTick +'+ contained
syn match puppetRegexOr "|" contained
"syn match puppetRegexSubName "['<][[:alnum:]]\+[>']" contains=puppetRegexAngBrack,puppetRegexTick contained
syn match puppetRegexSpecialChar "[?:imx]\|\(<?[=!]\)" contained
syn region puppetRegexComment start="(?#" skip="\\)" end=")" contained
" comments last overriding everything else
syn match puppetComment "\s*#.*$" contains=puppetTodo
syn region puppetComment start="/\*" end="\*/" contains=puppetTodo extend
syn keyword puppetTodo TODO NOTE FIXME XXX BUG HACK contained
syn match puppetComment "\s*#.*$" contains=puppetTodo,@Spell
syn region puppetMultilineComment start="/\*" end="\*/" contains=puppetTodo,@Spell
syn keyword puppetTodo TODO NOTE FIXME XXX BUG HACK contained
syn keyword puppetTodo TODO: NOTE: FIXME: XXX: BUG: HACK: contained
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
@ -90,15 +123,32 @@ if version >= 508 || !exists("did_puppet_syn_inits")
HiLink puppetVariable Identifier
HiLink puppetType Identifier
HiLink puppetKeyword Define
HiLink puppetKeyword Keyword
HiLink puppetComment Comment
HiLink puppetMultilineComment Comment
HiLink puppetString String
HiLink puppetParamKeyword String
HiLink puppetRegex Constant
HiLink puppetRegexParen Delimiter
HiLink puppetRegexBrace Delimiter
HiLink puppetRegexBrack Delimiter
HiLink puppetRegexAngBrack Delimiter
HiLink puppetRegexTick Delimiter
HiLink puppetRegexOr Delimiter
HiLink puppetRegexSubName Identifier
HiLink puppetRegexSpecChar SpecialChar
HiLink puppetRegexComment Comment
HiLink puppetParamKeyword Keyword
HiLink puppetParamDigits String
HiLink puppetNotVariable String
HiLink puppetParamSpecial Special
HiLink puppetParamSpecial Boolean
HiLink puppetSpecial Special
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
@ -108,10 +158,9 @@ if version >= 508 || !exists("did_puppet_syn_inits")
HiLink puppetParamName Identifier
HiLink puppetArgument Identifier
HiLink puppetFunction Function
HiLink puppetClass Include
delcommand HiLink
endif
let b:current_syntax = "puppet"
set iskeyword=-,:,@,48-57,_,192-255