Эх сурвалжийг харах

Merge pull request #51 from junegunn/public-api

Add plug#helptags and plug#load (#48)
Junegunn Choi 11 жил өмнө
parent
commit
f43067c7a5
3 өөрчлөгдсөн 66 нэмэгдсэн , 2 устгасан
  1. 26 2
      plug.vim
  2. 4 0
      test/run
  3. 36 0
      test/workflow.vader

+ 26 - 2
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 was 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)
@@ -369,13 +389,17 @@ function! s:update(force, ...)
   call s:update_impl(1, a:force, a:000)
 endfunction
 
-function! s:helptags()
+function! plug#helptags()
+  if !exists('g:plugs')
+    return s:err('plug#begin was not called')
+  endif
   for spec in values(g:plugs)
     let docd = join([spec.dir, 'doc'], '/')
     if isdirectory(docd)
       silent! execute 'helptags '. s:esc(docd)
     endif
   endfor
+  return 1
 endfunction
 
 function! s:syntax()
@@ -508,7 +532,7 @@ endfunction
 function! s:finish(pull)
   call append(3, '- Finishing ... ')
   redraw
-  call s:helptags()
+  call plug#helptags()
   call plug#end()
   call setline(4, getline(4) . 'Done!')
   normal! gg

+ 4 - 0
test/run

@@ -30,6 +30,10 @@ EOF
 
 make_dirs xxx/
 make_dirs xxx/after
+mkdir xxx/doc
+cat > xxx/doc/xxx.txt << DOC
+hello *xxx*
+DOC
 
 cat > /tmp/mini-vimrc << VIMRC
 set rtp+=vader.vim

+ 36 - 0
test/workflow.vader

@@ -761,6 +761,42 @@ Execute (Filetype-based on-demand loading):
   setf xxx
   AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
 
+**********************************************************************
+~ plug#helptags()
+**********************************************************************
+
+Execute (plug#helptags):
+  silent! call delete(expand('$PWD/xxx/doc/tags'))
+  Assert !filereadable(expand('$PWD/xxx/doc/tags'))
+  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)