mirror of
https://github.com/junegunn/vim-plug.git
synced 2025-12-08 01:44:44 +08:00
Fix #130 - Proper cleanup of on-demand loading triggers
This commit is contained in:
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
|
||||
|
||||
Reference in New Issue
Block a user