Support { 'do': ':VimCommand' } notation

Close #450
This commit is contained in:
Junegunn Choi 2016-07-13 23:01:41 +09:00
parent 460fbe82e0
commit 17996cedce
No known key found for this signature in database
GPG key ID: 254BC280FEF9C627
3 changed files with 32 additions and 4 deletions

View file

@ -201,6 +201,12 @@ Plug 'Shougo/vimproc.vim', { 'do': 'make' }
Plug 'Valloric/YouCompleteMe', { 'do': './install.py' }
```
If the value starts with `:`, it will be recognized as a Vim command.
```vim
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
```
If you need more control, you can pass a reference to a Vim function that
takes a single argument.

View file

@ -267,7 +267,7 @@ function! plug#end()
syntax enable
end
else
call s:reload()
call s:reload_plugins()
endif
endfunction
@ -275,9 +275,13 @@ function! s:loaded_names()
return filter(copy(g:plugs_order), 'get(s:loaded, v:val, 0)')
endfunction
function! s:reload()
function! s:load_plugin(spec)
call s:source(s:rtp(a:spec), 'plugin/**/*.vim', 'after/plugin/**/*.vim')
endfunction
function! s:reload_plugins()
for name in s:loaded_names()
call s:source(s:rtp(g:plugs[name]), 'plugin/**/*.vim', 'after/plugin/**/*.vim')
call s:load_plugin(g:plugs[name])
endfor
endfunction
@ -785,7 +789,12 @@ function! s:do(pull, force, todo)
let error = ''
let type = type(spec.do)
if type == s:TYPE.string
let error = s:bang(spec.do)
if spec.do[0] == ':'
call s:load_plugin(spec)
execute spec.do[1:]
else
let error = s:bang(spec.do)
endif
elseif type == s:TYPE.funcref
try
let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged')

View file

@ -933,11 +933,24 @@ Execute (Should not run when failed to update):
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/not-failed'),
\ 'vim-pseudocl/not-failed should exist'
Execute (Vim command with : prefix):
call plug#begin()
Plug 'junegunn/vim-pseudocl', { 'do': ':call setline(2, 12345)' }
call plug#end()
PlugInstall!
Log getline(1, '$')
AssertEqual '12345', getline(2)
q
**********************************************************************
~ Overriding `dir`
**********************************************************************
Execute (Using custom dir):
call plug#begin()
Plug 'junegunn/vim-easy-align'
call plug#end()
Assert isdirectory(g:plugs['vim-easy-align'].dir)
call RmRf('/tmp/vim-plug-test/easy-align')