Allow updating subset of plugins
This commit extends `PlugInstall` and `PlugUpdate` command to allow updating only a subset of plugins as follows: " With tab completion of plugin names :PlugInstall vim-easy-align seoul256 :PlugUpdate vim-easy-align seoul256
This commit is contained in:
parent
4d32762432
commit
5168cd50db
|
@ -61,9 +61,9 @@ before the call.
|
||||||
### Commands
|
### Commands
|
||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
| ---------------------- | ------------------------------------------------------------------ |
|
| --------------------------------- | ------------------------------------------------------------------ |
|
||||||
| PlugInstall [#threads] | Install plugins |
|
| PlugInstall [name ...] [#threads] | Install plugins |
|
||||||
| PlugUpdate [#threads] | Install or update plugins |
|
| PlugUpdate [name ...] [#threads] | Install or update plugins |
|
||||||
| PlugClean[!] | Remove unused directories (bang version will clean without prompt) |
|
| PlugClean[!] | Remove unused directories (bang version will clean without prompt) |
|
||||||
| PlugUpgrade | Upgrade vim-plug itself |
|
| PlugUpgrade | Upgrade vim-plug itself |
|
||||||
| PlugStatus | Check the status of plugins |
|
| PlugStatus | Check the status of plugins |
|
||||||
|
|
42
plug.vim
42
plug.vim
|
@ -24,7 +24,7 @@
|
||||||
" You can change the location of the plugins with plug#begin(path) call.
|
" You can change the location of the plugins with plug#begin(path) call.
|
||||||
"
|
"
|
||||||
"
|
"
|
||||||
" Copyright (c) 2013 Junegunn Choi
|
" Copyright (c) 2014 Junegunn Choi
|
||||||
"
|
"
|
||||||
" MIT License
|
" MIT License
|
||||||
"
|
"
|
||||||
|
@ -93,8 +93,8 @@ function! plug#begin(...)
|
||||||
let g:plugs_order = []
|
let g:plugs_order = []
|
||||||
|
|
||||||
command! -nargs=+ -bar Plug call s:add(1, <args>)
|
command! -nargs=+ -bar Plug call s:add(1, <args>)
|
||||||
command! -nargs=* PlugInstall call s:install(<f-args>)
|
command! -nargs=* -complete=customlist,s:names PlugInstall call s:install(<f-args>)
|
||||||
command! -nargs=* PlugUpdate call s:update(<f-args>)
|
command! -nargs=* -complete=customlist,s:names PlugUpdate call s:update(<f-args>)
|
||||||
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
||||||
command! -nargs=0 PlugUpgrade if s:upgrade() | execute "source ". s:me | endif
|
command! -nargs=0 PlugUpgrade if s:upgrade() | execute "source ". s:me | endif
|
||||||
command! -nargs=0 PlugStatus call s:status()
|
command! -nargs=0 PlugStatus call s:status()
|
||||||
|
@ -372,19 +372,35 @@ function! s:finish(pull)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:update_impl(pull, args)
|
function! s:names(...)
|
||||||
let threads = len(a:args) > 0 ? a:args[0] : get(g:, 'plug_threads', 16)
|
return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:update_impl(pull, args) abort
|
||||||
|
let args = copy(a:args)
|
||||||
|
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
||||||
|
\ remove(args, -1) : get(g:, 'plug_threads', 16)
|
||||||
|
|
||||||
|
let todo = empty(args) ? g:plugs :
|
||||||
|
\ filter(copy(g:plugs), 'index(args, v:key) >= 0')
|
||||||
|
|
||||||
|
if empty(todo)
|
||||||
|
echohl WarningMsg
|
||||||
|
echo 'No plugin to '. (a:pull ? 'update' : 'install') . '.'
|
||||||
|
echohl None
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
call s:prepare()
|
call s:prepare()
|
||||||
call append(0, a:pull ? 'Updating plugins' : 'Installing plugins')
|
call append(0, a:pull ? 'Updating plugins' : 'Installing plugins')
|
||||||
call append(1, '['. s:lpad('', len(g:plugs)) .']')
|
call append(1, '['. s:lpad('', len(todo)) .']')
|
||||||
normal! 2G
|
normal! 2G
|
||||||
redraw
|
redraw
|
||||||
|
|
||||||
if has('ruby') && threads > 1
|
if has('ruby') && threads > 1
|
||||||
call s:update_parallel(a:pull, threads)
|
call s:update_parallel(a:pull, todo, threads)
|
||||||
else
|
else
|
||||||
call s:update_serial(a:pull)
|
call s:update_serial(a:pull, todo)
|
||||||
endif
|
endif
|
||||||
call s:finish(a:pull)
|
call s:finish(a:pull)
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -413,10 +429,10 @@ function! s:update_progress(pull, cnt, bar, total)
|
||||||
redraw
|
redraw
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:update_serial(pull)
|
function! s:update_serial(pull, todo)
|
||||||
let st = reltime()
|
let st = reltime()
|
||||||
let base = g:plug_home
|
let base = g:plug_home
|
||||||
let todo = copy(g:plugs)
|
let todo = copy(a:todo)
|
||||||
let total = len(todo)
|
let total = len(todo)
|
||||||
let done = {}
|
let done = {}
|
||||||
let bar = ''
|
let bar = ''
|
||||||
|
@ -468,7 +484,7 @@ function! s:update_serial(pull)
|
||||||
call setline(1, "Updated. Elapsed time: " . split(reltimestr(reltime(st)))[0] . ' sec.')
|
call setline(1, "Updated. Elapsed time: " . split(reltimestr(reltime(st)))[0] . ' sec.')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:update_parallel(pull, threads)
|
function! s:update_parallel(pull, todo, threads)
|
||||||
ruby << EOF
|
ruby << EOF
|
||||||
def esc arg
|
def esc arg
|
||||||
%["#{arg.gsub('"', '\"')}"]
|
%["#{arg.gsub('"', '\"')}"]
|
||||||
|
@ -482,7 +498,7 @@ function! s:update_parallel(pull, threads)
|
||||||
iswin = VIM::evaluate('s:is_win').to_i == 1
|
iswin = VIM::evaluate('s:is_win').to_i == 1
|
||||||
pull = VIM::evaluate('a:pull').to_i == 1
|
pull = VIM::evaluate('a:pull').to_i == 1
|
||||||
base = VIM::evaluate('g:plug_home')
|
base = VIM::evaluate('g:plug_home')
|
||||||
all = VIM::evaluate('copy(g:plugs)')
|
all = VIM::evaluate('copy(a:todo)')
|
||||||
limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
|
limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
|
||||||
nthr = VIM::evaluate('a:threads').to_i
|
nthr = VIM::evaluate('a:threads').to_i
|
||||||
cd = iswin ? 'cd /d' : 'cd'
|
cd = iswin ? 'cd /d' : 'cd'
|
||||||
|
@ -494,7 +510,7 @@ function! s:update_parallel(pull, threads)
|
||||||
take1 = proc { mtx.synchronize { running && all.shift } }
|
take1 = proc { mtx.synchronize { running && all.shift } }
|
||||||
logh = proc {
|
logh = proc {
|
||||||
cnt = done.length
|
cnt = done.length
|
||||||
tot = VIM::evaluate('len(g:plugs)') || tot
|
tot = VIM::evaluate('len(a:todo)') || tot
|
||||||
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
|
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
|
||||||
$curbuf[2] = '[' + bar.ljust(tot) + ']'
|
$curbuf[2] = '[' + bar.ljust(tot) + ']'
|
||||||
VIM::command('normal! 2G')
|
VIM::command('normal! 2G')
|
||||||
|
|
|
@ -296,6 +296,62 @@ Execute (Plug window in a new tab):
|
||||||
q
|
q
|
||||||
q
|
q
|
||||||
|
|
||||||
|
**********************************************************************
|
||||||
|
~ On-demand loading / Partial installation/update ~
|
||||||
|
**********************************************************************
|
||||||
|
|
||||||
|
Execute (Trying to execute on-demand commands when plugin is not installed):
|
||||||
|
call plug#begin()
|
||||||
|
Plug 'junegunn/vim-easy-align', { 'on': ['EasyAlign', 'LiveEasyAlign'] }
|
||||||
|
call plug#end()
|
||||||
|
|
||||||
|
Assert exists(':EasyAlign')
|
||||||
|
Assert exists(':LiveEasyAlign')
|
||||||
|
AssertThrows EasyAlign
|
||||||
|
AssertThrows LiveEasyAlign
|
||||||
|
Assert !exists(':EasyAlign')
|
||||||
|
Assert !exists(':LiveEasyAlign')
|
||||||
|
|
||||||
|
Execute (New set of plugins):
|
||||||
|
call plug#begin()
|
||||||
|
Plug 'junegunn/vim-fnr' " Depends on vim-pseudocl
|
||||||
|
Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
|
||||||
|
Plug 'junegunn/vim-redis', { 'for': 'redis' }
|
||||||
|
call plug#end()
|
||||||
|
|
||||||
|
Execute (Check commands):
|
||||||
|
Assert !exists(':FNR'), 'FNR command should not be found'
|
||||||
|
Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
|
||||||
|
|
||||||
|
Execute (Partial PlugInstall):
|
||||||
|
PlugInstall vim-fnr vim-easy-align
|
||||||
|
PlugInstall vim-fnr vim-easy-align 1
|
||||||
|
q
|
||||||
|
|
||||||
|
Given (Unaligned code):
|
||||||
|
a=1
|
||||||
|
aa=2
|
||||||
|
|
||||||
|
Execute (Check installed plugins):
|
||||||
|
Assert exists(':FNR'), 'FNR command should be found'
|
||||||
|
Assert exists(':EasyAlign'), 'EasyAlign command should be found'
|
||||||
|
Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
|
||||||
|
%EasyAlign=
|
||||||
|
|
||||||
|
Expect (Aligned code):
|
||||||
|
a = 1
|
||||||
|
aa = 2
|
||||||
|
|
||||||
|
Given (nothing):
|
||||||
|
Execute (Partial PlugUpdate):
|
||||||
|
PlugUpdate vim-redis
|
||||||
|
q
|
||||||
|
|
||||||
|
Execute (On-demand loading based on filetypes):
|
||||||
|
Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
|
||||||
|
set ft=redis
|
||||||
|
Assert exists(':RedisExecute'), 'RedisExecute command is now found'
|
||||||
|
|
||||||
Execute (Cleanup):
|
Execute (Cleanup):
|
||||||
call system('rm -rf '.temp_plugged)
|
call system('rm -rf '.temp_plugged)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user