mirror of
https://github.com/junegunn/vim-plug.git
synced 2024-12-19 10:35:38 -07:00
Fix #130 - Proper cleanup of on-demand loading triggers
This commit is contained in:
parent
48514768c2
commit
044c3a67c4
32
plug.vim
32
plug.vim
@ -99,6 +99,7 @@ function! plug#begin(...)
|
||||
let g:plug_home = home
|
||||
let g:plugs = {}
|
||||
let g:plugs_order = []
|
||||
let s:triggers = {}
|
||||
|
||||
call s:define_commands()
|
||||
return 1
|
||||
@ -156,6 +157,7 @@ function! plug#end()
|
||||
endif
|
||||
|
||||
if has_key(plug, 'on')
|
||||
let s:triggers[name] = { 'map': [], 'cmd': [] }
|
||||
for cmd in s:to_a(plug.on)
|
||||
if cmd =~ '^<Plug>.\+'
|
||||
if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
|
||||
@ -166,10 +168,14 @@ function! plug#end()
|
||||
\ mode, cmd, map_prefix, string(cmd), string(name), key_prefix)
|
||||
endfor
|
||||
endif
|
||||
elseif !exists(':'.cmd)
|
||||
execute printf(
|
||||
\ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
|
||||
\ cmd, string(cmd), string(name))
|
||||
call add(s:triggers[name].map, cmd)
|
||||
elseif cmd =~ '^[A-Z]'
|
||||
if !exists(':'.cmd)
|
||||
execute printf(
|
||||
\ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "<bang>", <line1>, <line2>, <q-args>, %s)',
|
||||
\ cmd, string(cmd), string(name))
|
||||
endif
|
||||
call add(s:triggers[name].cmd, cmd)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
@ -324,8 +330,23 @@ function! plug#load(...)
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:remove_triggers(name)
|
||||
if !has_key(s:triggers, a:name)
|
||||
return
|
||||
endif
|
||||
for cmd in s:triggers[a:name].cmd
|
||||
execute 'delc' cmd
|
||||
endfor
|
||||
for map in s:triggers[a:name].map
|
||||
execute 'unmap' map
|
||||
execute 'iunmap' map
|
||||
endfor
|
||||
call remove(s:triggers, a:name)
|
||||
endfunction
|
||||
|
||||
function! s:lod(names, types)
|
||||
for name in a:names
|
||||
call s:remove_triggers(name)
|
||||
let s:loaded[name] = 1
|
||||
endfor
|
||||
call s:reorg_rtp()
|
||||
@ -346,14 +367,11 @@ function! s:lod_ft(pat, names)
|
||||
endfunction
|
||||
|
||||
function! s:lod_cmd(cmd, bang, l1, l2, args, name)
|
||||
execute 'delc' a:cmd
|
||||
call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
|
||||
function! s:lod_map(map, name, prefix)
|
||||
execute 'unmap' a:map
|
||||
execute 'iunmap' a:map
|
||||
call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
let extra = ''
|
||||
while 1
|
||||
|
@ -1103,6 +1103,41 @@ Execute (#114 Should not contain empty path in &rtp):
|
||||
Assert &rtp !~ '^,', 'Comma prefix'
|
||||
Assert &rtp !~ ',$', 'Comma suffix'
|
||||
|
||||
**********************************************************************
|
||||
Execute (#130 Proper cleanup of on-demand loading triggers):
|
||||
augroup PlugLOD
|
||||
autocmd!
|
||||
augroup END
|
||||
|
||||
" Cleared on command
|
||||
call plug#begin('$TMPDIR/plugged')
|
||||
Plug 'junegunn/vim-emoji', { 'on': ['EmojiCommand', 'EmojiCommand2', '<Plug>(EmojiMapping)'] }
|
||||
call plug#end()
|
||||
PlugInstall | q
|
||||
|
||||
Assert exists(':EmojiCommand'), 'EmojiCommand not defined'
|
||||
Assert exists(':EmojiCommand2'), 'EmojiCommand2 not defined'
|
||||
Assert !empty(mapcheck('<Plug>(EmojiMapping)')), '<Plug>(EmojiMapping) not defined'
|
||||
|
||||
silent! EmojiCommand
|
||||
|
||||
Assert !exists(':EmojiCommand'), 'EmojiCommand defined'
|
||||
Assert !exists(':EmojiCommand2'), 'EmojiCommand2 defined'
|
||||
Assert empty(mapcheck('<Plug>(EmojiMapping)')), '<Plug>(EmojiMapping) defined'
|
||||
|
||||
" Cleared on FileType
|
||||
call plug#begin('$TMPDIR/plugged')
|
||||
Plug 'junegunn/vim-emoji', { 'on': ['EmojiCommandExtra', '<Plug>(EmojiMappingExtra)'], 'for': ['emoji'] }
|
||||
call plug#end()
|
||||
|
||||
Assert exists(':EmojiCommandExtra'), 'EmojiCommandExtra not defined'
|
||||
Assert !empty(mapcheck('<Plug>(EmojiMappingExtra)')), '<Plug>(EmojiMappingExtra) not defined'
|
||||
|
||||
setf emoji
|
||||
|
||||
Assert !exists(':EmojiCommandExtra'), 'EmojiCommandExtra defined'
|
||||
Assert empty(mapcheck('<Plug>(EmojiMappingExtra)')), '<Plug>(EmojiMappingExtra) defined'
|
||||
|
||||
Execute (Cleanup):
|
||||
silent! call system('rm -rf '.temp_plugged)
|
||||
silent! call system('rm -rf '.temp_plugged)
|
||||
|
Loading…
Reference in New Issue
Block a user