mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-19 18:47:29 -07:00
Merge pull request #232 from junegunn/user-autocmd
Trigger User autocmd when plugin is loaded on demand (#231)
This commit is contained in:
commit
018b48e071
@ -134,6 +134,10 @@ Plug 'kovisoft/paredit', { 'for': ['clojure', 'scheme'] }
|
|||||||
|
|
||||||
" On-demand loading on both conditions
|
" On-demand loading on both conditions
|
||||||
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' }
|
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
|
`for` option is generally not needed as most plugins for specific file types
|
||||||
|
3
plug.vim
3
plug.vim
@ -388,6 +388,9 @@ function! s:lod(names, types)
|
|||||||
for dir in a:types
|
for dir in a:types
|
||||||
call s:source(rtp, dir.'/**/*.vim')
|
call s:source(rtp, dir.'/**/*.vim')
|
||||||
endfor
|
endfor
|
||||||
|
if exists('#User#'.name)
|
||||||
|
execute 'doautocmd User' name
|
||||||
|
endif
|
||||||
endfor
|
endfor
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -371,11 +371,16 @@ Execute (New set of plugins):
|
|||||||
Plug 'junegunn/vim-pseudocl'
|
Plug 'junegunn/vim-pseudocl'
|
||||||
Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
|
Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
|
||||||
Plug 'junegunn/vim-redis', { 'for': 'redis' }
|
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()
|
call plug#end()
|
||||||
|
|
||||||
Execute (Check commands):
|
Execute (Check commands):
|
||||||
Assert !exists(':FNR'), 'FNR command should not be found'
|
Assert !exists(':FNR'), 'FNR command should not be found'
|
||||||
Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
|
Assert !exists(':RedisExecute'), 'RedisExecute command should not be found'
|
||||||
|
Assert empty(user_autocmd)
|
||||||
|
|
||||||
Execute (Partial PlugInstall):
|
Execute (Partial PlugInstall):
|
||||||
PlugInstall vim-fnr vim-easy-align
|
PlugInstall vim-fnr vim-easy-align
|
||||||
@ -405,6 +410,10 @@ Expect (Aligned code):
|
|||||||
a = 1
|
a = 1
|
||||||
aa = 2
|
aa = 2
|
||||||
|
|
||||||
|
Then (autocmd executed):
|
||||||
|
Assert user_autocmd.easy_align
|
||||||
|
AssertEqual 1, len(user_autocmd)
|
||||||
|
|
||||||
Given:
|
Given:
|
||||||
Execute (Partial PlugUpdate):
|
Execute (Partial PlugUpdate):
|
||||||
PlugUpdate vim-redis
|
PlugUpdate vim-redis
|
||||||
@ -414,6 +423,12 @@ Execute (On-demand loading based on filetypes):
|
|||||||
Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
|
Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
|
||||||
set ft=redis
|
set ft=redis
|
||||||
Assert exists(':RedisExecute'), 'RedisExecute command is now found'
|
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
|
~ Local (unmanaged) plugins
|
||||||
|
Loading…
Reference in New Issue
Block a user