quite a refactor

- batch process just iterates through the lines and calls specified
action
- individual actions give visual feedback aswell
- allow Helptags command as a part of installation process
This commit is contained in:
gmarik 2011-08-19 00:35:45 -05:00
parent 9a82aaf500
commit d41ce3ea35
2 changed files with 64 additions and 36 deletions

View File

@ -3,10 +3,10 @@ func! vundle#installer#new(bang, ...) abort
\ g:bundles :
\ map(copy(a:000), 'vundle#config#init_bundle(v:val, {})')
let names = map(copy(bundles), 'v:val.name_spec')
call vundle#scripts#view('Installer',['" Installing bundles'], names)
let names = vundle#scripts#bundle_names(map(copy(bundles), 'v:val.name_spec'))
call vundle#scripts#view('Installer',['" Installing bundles'], names + ['Helptags'])
call s:process(a:bang, 'install', names)
call s:process(a:bang, (a:bang ? 'I':'i'))
call vundle#config#require(bundles)
@ -14,39 +14,21 @@ func! vundle#installer#new(bang, ...) abort
endf
func! s:process(bang, func_name, items)
func! s:process(bang, cmd)
let msg = ''
redraw!
sleep 1m
for n in a:items
let lines = (getline('.','$')[0:-2])
for line in lines
redraw!
echo 'Processing '.n
call s:sign('active')
exec ':norm '.a:cmd
sleep 1m
let status = call('vundle#installer#'.a:func_name, [a:bang, n])
call s:sign(status)
redraw!
if 'updated' == status
echo n.' installed'
elseif 'todate' == status
echo n.' already installed'
elseif 'deleted' == status
echo n.' deleted'
elseif 'error' == status
echohl Error
echo 'Error processing '.n
echohl None
sleep 1
let msg = 'With errors, press `l` to view log'
else
throw 'whoops, unknown status:'.status
if 'error' == g:vundle_last_status
let msg = 'With erros; press l to view log'
endif
" goto next one
@ -59,6 +41,40 @@ func! s:process(bang, func_name, items)
echo 'Done! '.msg
endf
func! vundle#installer#run(func_name, name, ...) abort
let n = a:name
echo 'Processing '.n
call s:sign('active')
sleep 1m
let status = call(a:func_name, a:1)
call s:sign(status)
redraw!
if 'updated' == status
echo n.' installed'
elseif 'todate' == status
echo n.' already installed'
elseif 'deleted' == status
echo n.' deleted'
elseif 'error' == status
echohl Error
echo 'Error processing '.n
echohl None
sleep 1
else
throw 'whoops, unknown status:'.status
endif
let g:vundle_last_status = status
return status
endf
func! s:sign(status)
if (!has('signs'))
return
@ -75,6 +91,11 @@ func! vundle#installer#install(bang, name) abort
return s:sync(a:bang, b)
endf
func! vundle#installer#docs() abort
call vundle#installer#helptags(g:bundles)
return 'updated'
endf
func! vundle#installer#helptags(bundles) abort
let bundle_dirs = map(copy(a:bundles),'v:val.rtpath()')
let help_dirs = filter(bundle_dirs, 's:has_doc(v:val)')
@ -90,7 +111,8 @@ func! vundle#installer#helptags(bundles) abort
endf
func! vundle#installer#list(bang) abort
call vundle#scripts#view('list', ['" My Bundles'], map(copy(g:bundles), 'v:val.name_spec'))
let bundles = vundle#scripts#bundle_names(map(copy(g:bundles), 'v:val.name_spec'))
call vundle#scripts#view('list', ['" My Bundles'], bundles)
redraw!
echo len(g:bundles).' bundles configured'
endf
@ -106,14 +128,14 @@ func! vundle#installer#clean(bang) abort
let names = []
else
let headers = ['" Removing bundles:']
let names = map(copy(x_dirs), 'fnamemodify(v:val, ":t")')
let names = vundle#scripts#bundle_names(map(copy(x_dirs), 'fnamemodify(v:val, ":t")'))
end
call vundle#scripts#view('clean', headers, names)
redraw!
if (a:bang || empty(names) || input('Continute ? [ y/n ]:') =~? 'y')
call s:process(a:bang, 'delete', names)
call s:process(a:bang, 'd')
endif
endf

View File

@ -8,7 +8,7 @@ func! vundle#scripts#all(bang, ...)
" TODO: highlight matches
let b:match = a:1
endif
call vundle#scripts#view('search',info, reverse(matches))
call vundle#scripts#view('search',info, vundle#scripts#bundle_names(reverse(matches)))
redraw!
echo len(matches).' bundles found'
endf
@ -33,19 +33,22 @@ func! s:view_log()
wincmd P | wincmd H
endf
func vundle#scripts#bundle_names(names)
return map(copy(a:names), ' printf("Bundle ' ."'%s'".'", v:val) ')
endf
func! vundle#scripts#view(title, headers, results)
if exists('g:vundle_view')
exec g:vundle_view.'bd!'
endif
let results = map(copy(a:results), ' printf("Bundle ' ."'%s'".'", v:val) ')
exec 'silent pedit [Vundle] '.a:title
wincmd P | wincmd H
let g:vundle_view = bufnr('%')
call append(0, a:headers + results)
call append(0, a:headers + a:results)
setl buftype=nofile
setl noswapfile
@ -57,9 +60,12 @@ func! vundle#scripts#view(title, headers, results)
setl ft=vundle
setl syntax=vim
syn keyword vimCommand Bundle
syn keyword vimCommand Helptags
com! -buffer -bang -nargs=1 DeleteBundle call vundle#installer#run('vundle#installer#delete', split(<q-args>,',')[0], ['!' == '<bang>', <args>])
com! -buffer -bang -nargs=? InstallBundle call vundle#installer#run('vundle#installer#install', split(<q-args>,',')[0], ['!' == '<bang>', <q-args>])
com! -buffer -bang -nargs=? InstallHelptags call vundle#installer#run('vundle#installer#docs', 'helptags', [])
com! -buffer -bang -nargs=1 DeleteBundle call vundle#installer#delete('!' == '<bang>', <args>)
com! -buffer -bang -nargs=? InstallBundle call vundle#installer#install('!' == '<bang>', <q-args>)
com! -buffer -nargs=0 VundleLog call s:view_log()
nnoremap <buffer> q :silent bd!<CR>