From e6a594f1ad71dd2c99600956670d06b141a27427 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 27 Jul 2014 11:28:53 +0900 Subject: [PATCH] Change post-hook function to take a dictionary for more control --- README.md | 12 +++++++++--- plug.vim | 5 +++-- test/workflow.vader | 12 ++++++------ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e17a198..2a68a5b 100644 --- a/README.md +++ b/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') } diff --git a/plug.vim b/plug.vim index d23a7ac..4520843 100644 --- a/plug.vim +++ b/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 diff --git a/test/workflow.vader b/test/workflow.vader index f09acea..16fca9a 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -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)