Browse Source

Add plug#load() (#48)

Junegunn Choi 11 năm trước cách đây
mục cha
commit
f1b8832a13
2 tập tin đã thay đổi với 46 bổ sung0 xóa
  1. 20 0
      plug.vim
  2. 26 0
      test/workflow.vader

+ 20 - 0
plug.vim

@@ -266,6 +266,26 @@ function! s:reorg_rtp()
   endif
 endfunction
 
+function! plug#load(...)
+  if a:0 == 0
+    return s:err('Argument missing: plugin name(s) required')
+  endif
+  if !exists('g:plugs')
+    return s:err('plug#begin is not called')
+  endif
+  let unknowns = filter(copy(a:000), '!has_key(g:plugs, v:val)')
+  if !empty(unknowns)
+    let s = len(unknowns) > 1 ? 's' : ''
+    return s:err(printf('Unknown plugin%s: %s', s, join(unknowns, ', ')))
+  end
+  for name in a:000
+    call s:lod(g:plugs[name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
+  endfor
+  call s:reorg_rtp()
+  silent! doautocmd BufRead
+  return 1
+endfunction
+
 function! s:lod(plug, types)
   let rtp = s:rtp(a:plug)
   call s:add_rtp(rtp)

+ 26 - 0
test/workflow.vader

@@ -771,6 +771,32 @@ Execute (plug#helptags):
   AssertEqual 1, plug#helptags()
   Assert filereadable(expand('$PWD/xxx/doc/tags'))
 
+**********************************************************************
+~ plug#load()
+**********************************************************************
+
+Execute (plug#load - invalid arguments):
+  AssertEqual 0, plug#load()
+  AssertEqual 0, plug#load('non-existent-plugin')
+  AssertEqual 0, plug#load('non-existent-plugin', 'another-non-existent-plugin')
+  AssertEqual 1, plug#load('xxx')
+  AssertEqual 0, plug#load('xxx', 'non-existent-plugin')
+  AssertEqual 0, plug#load('non-existent-plugin', 'xxx')
+
+Execute (plug#load):
+  call plug#begin()
+  Plug 'junegunn/rust.vim', { 'on': [] }
+  call plug#end()
+  PlugInstall
+  q
+
+  setf xxx
+  f test.rs
+  Log &filetype
+
+  AssertEqual 1, plug#load('rust.vim')
+  AssertEqual 'rust', &filetype
+
 Before:
 Execute (Cleanup):
   silent! call system('rm -rf '.temp_plugged)