From 17996cedceaab2eb98bd39a666f472e547930c54 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 13 Jul 2016 23:01:41 +0900 Subject: [PATCH] Support { 'do': ':VimCommand' } notation Close #450 --- README.md | 6 ++++++ plug.vim | 17 +++++++++++++---- test/workflow.vader | 13 +++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 84d7b45..c26afff 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/plug.vim b/plug.vim index 0d0e409..866db9c 100644 --- a/plug.vim +++ b/plug.vim @@ -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') diff --git a/test/workflow.vader b/test/workflow.vader index f659bad..bcc2f8e 100644 --- a/test/workflow.vader +++ b/test/workflow.vader @@ -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')