Change post-hook function to take a dictionary for more control
This commit is contained in:
parent
e741d02ad0
commit
e6a594f1ad
3 changed files with 18 additions and 11 deletions
12
README.md
12
README.md
|
@ -129,11 +129,17 @@ In that case, use `do` option to describe the task to be performed.
|
|||
Plug 'Valloric/YouCompleteMe', { 'do': './install.sh' }
|
||||
```
|
||||
|
||||
If you need more control, you can pass a reference to a Vim function instead.
|
||||
If you need more control, you can pass a reference to a Vim function that
|
||||
takes a single argument.
|
||||
|
||||
```vim
|
||||
function! BuildYCM()
|
||||
" ...
|
||||
function! BuildYCM(info)
|
||||
" info is a dictionary with two fields
|
||||
" - name: name of the plugin
|
||||
" - status: 'installed' or 'updated'
|
||||
if a:info.status == 'installed'
|
||||
!./install.sh
|
||||
endif
|
||||
endfunction
|
||||
|
||||
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
|
||||
|
|
5
plug.vim
5
plug.vim
|
@ -454,7 +454,8 @@ function! s:do(pull, todo)
|
|||
continue
|
||||
endif
|
||||
execute 'cd '.s:esc(spec.dir)
|
||||
if has_key(s:prev_update.new, name) || (a:pull &&
|
||||
let installed = has_key(s:prev_update.new, name)
|
||||
if installed || (a:pull &&
|
||||
\ !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"')))
|
||||
call append(3, '- Post-update hook for '. name .' ... ')
|
||||
let type = type(spec.do)
|
||||
|
@ -470,7 +471,7 @@ function! s:do(pull, todo)
|
|||
endtry
|
||||
elseif type == s:TYPE.funcref
|
||||
try
|
||||
call spec.do()
|
||||
call spec.do({ 'name': name, 'status': (installed ? 'installed' : 'updated') })
|
||||
let result = 'Done!'
|
||||
catch
|
||||
let result = 'Error: ' . v:exception
|
||||
|
|
|
@ -644,8 +644,8 @@ Execute (When already updated):
|
|||
\ 'vim-pseudocl/updated2 should exist'
|
||||
|
||||
Execute (Using Funcref):
|
||||
function! PlugUpdated()
|
||||
call system('touch me')
|
||||
function! PlugUpdated(info)
|
||||
call system('touch '. a:info.name . a:info.status . len(a:info))
|
||||
endfunction
|
||||
|
||||
call plug#begin()
|
||||
|
@ -659,10 +659,10 @@ Execute (Using Funcref):
|
|||
PlugUpdate
|
||||
Log getline(1, '$')
|
||||
q
|
||||
Assert filereadable(g:plugs['vim-easy-align'].dir.'/me'),
|
||||
\ 'vim-easy-align/me should exist'
|
||||
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/me'),
|
||||
\ 'vim-pseudocl/me should exist'
|
||||
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated2'),
|
||||
\ 'vim-easy-align/vim-easy-alignupdated2 should exist'
|
||||
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled2'),
|
||||
\ 'vim-pseudocl/vim-pseudoclinstalled2 should exist'
|
||||
|
||||
Execute (Cleanup):
|
||||
call system('rm -rf '.temp_plugged)
|
||||
|
|
Loading…
Reference in a new issue