Merge pull request #232 from junegunn/user-autocmd

Trigger User autocmd when plugin is loaded on demand (#231)
This commit is contained in:
Junegunn Choi 2015-05-20 02:10:01 +09:00
commit 018b48e071
3 changed files with 22 additions and 0 deletions

View File

@ -134,6 +134,10 @@ Plug 'kovisoft/paredit', { 'for': ['clojure', 'scheme'] }
" On-demand loading on both conditions
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' }
" Code to execute when the plugin is loaded on demand
Plug 'Valloric/YouCompleteMe', { 'for': 'cpp' }
autocmd! User YouCompleteMe call youcompleteme#Enable()
```
`for` option is generally not needed as most plugins for specific file types

View File

@ -388,6 +388,9 @@ function! s:lod(names, types)
for dir in a:types
call s:source(rtp, dir.'/**/*.vim')
endfor
if exists('#User#'.name)
execute 'doautocmd User' name
endif
endfor
endfunction

View File

@ -371,11 +371,16 @@ Execute (New set of plugins):
Plug 'junegunn/vim-pseudocl'
Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
Plug 'junegunn/vim-redis', { 'for': 'redis' }
let user_autocmd = {}
autocmd! User vim-fnr let user_autocmd.fnr = 1
autocmd! User vim-easy-align let user_autocmd.easy_align = 1
autocmd! User vim-redis let user_autocmd.redis = 1
call plug#end()
Execute (Check commands):
Assert !exists(':FNR'), 'FNR command should not be found'
Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
Assert empty(user_autocmd)
Execute (Partial PlugInstall):
PlugInstall vim-fnr vim-easy-align
@ -405,6 +410,10 @@ Expect (Aligned code):
a = 1
aa = 2
Then (autocmd executed):
Assert user_autocmd.easy_align
AssertEqual 1, len(user_autocmd)
Given:
Execute (Partial PlugUpdate):
PlugUpdate vim-redis
@ -414,6 +423,12 @@ 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'
Assert user_autocmd.redis
AssertEqual 2, len(user_autocmd)
Then:
autocmd! User
unlet user_autocmd
**********************************************************************
~ Local (unmanaged) plugins