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

View File

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