mirror of
https://github.com/junegunn/vim-plug.git
synced 2025-12-07 01:24:27 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61b77bc8e8 | ||
|
|
fe7c7e7b40 | ||
|
|
25afdf138c | ||
|
|
b36fd34da0 | ||
|
|
7e55690f19 | ||
|
|
30ef53d832 |
14
README.md
14
README.md
@@ -16,7 +16,6 @@ Somewhere between [Pathogen](https://github.com/tpope/vim-pathogen) and
|
||||
- Smallest possible feature set
|
||||
- Branch/tag support
|
||||
- On-demand loading
|
||||
- Dependency resolution using `Plugfile` (experimental)
|
||||
|
||||
### Cons.
|
||||
|
||||
@@ -51,8 +50,11 @@ Plug 'https://github.com/junegunn/vim-github-dashboard.git'
|
||||
" Plugin options
|
||||
Plug 'nsf/gocode', { 'tag': 'go.weekly.2012-03-13', 'rtp': 'vim' }
|
||||
|
||||
" Locally-managed plugin
|
||||
Plug '~/.fzf'
|
||||
" Plugin outside ~/.vim/plugged with post-update hook
|
||||
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
|
||||
|
||||
" Unmanaged plugin (manually installed and updated)
|
||||
Plug '~/my-prototype-plugin'
|
||||
|
||||
call plug#end()
|
||||
```
|
||||
@@ -163,15 +165,11 @@ let g:fzf_install = 'yes | ./install'
|
||||
Plug 'junegunn/fzf', { 'do': g:fzf_install }
|
||||
```
|
||||
|
||||
### Dependency resolution
|
||||
|
||||
See [Dependency
|
||||
Resolution](https://github.com/junegunn/vim-plug/wiki/Dependency-Resolution).
|
||||
|
||||
### Articles
|
||||
|
||||
- [Writing my own Vim plugin manager](http://junegunn.kr/2013/09/writing-my-own-vim-plugin-manager)
|
||||
- [Thoughts on Vim plugin dependency](http://junegunn.kr/2013/09/thoughts-on-vim-plugin-dependency)
|
||||
- *Support for Plugfile has been removed since 0.5.0*
|
||||
- [Vim plugins and startup time](http://junegunn.kr/2014/07/vim-plugins-and-startup-time)
|
||||
|
||||
### FAQ/Troubleshooting
|
||||
|
||||
301
plug.vim
301
plug.vim
@@ -25,8 +25,11 @@
|
||||
" " Plugin options
|
||||
" Plug 'nsf/gocode', { 'tag': 'go.weekly.2012-03-13', 'rtp': 'vim' }
|
||||
"
|
||||
" " Locally-managed plugin
|
||||
" Plug '~/.fzf'
|
||||
" " Plugin outside ~/.vim/plugged with post-update hook
|
||||
" Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
|
||||
"
|
||||
" " Unmanaged plugin (manually installed and updated)
|
||||
" Plug '~/my-prototype-plugin'
|
||||
"
|
||||
" call plug#end()
|
||||
"
|
||||
@@ -66,12 +69,11 @@ let s:cpo_save = &cpo
|
||||
set cpo&vim
|
||||
|
||||
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
|
||||
let s:plug_file = 'Plugfile'
|
||||
let s:plug_buf = -1
|
||||
let s:mac_gui = has('gui_macvim') && has('gui_running')
|
||||
let s:is_win = has('win32') || has('win64')
|
||||
let s:me = expand('<sfile>:p')
|
||||
let s:base_spec = { 'branch': 'master', 'frozen': 0, 'local': 0 }
|
||||
let s:base_spec = { 'branch': 'master', 'frozen': 0 }
|
||||
let s:TYPE = {
|
||||
\ 'string': type(''),
|
||||
\ 'list': type([]),
|
||||
@@ -106,7 +108,7 @@ function! plug#begin(...)
|
||||
" we want to keep track of the order plugins where registered.
|
||||
let g:plugs_order = []
|
||||
|
||||
command! -nargs=+ -bar Plug call s:add(1, <args>)
|
||||
command! -nargs=+ -bar Plug call s:add(<args>)
|
||||
command! -nargs=* -complete=customlist,s:names PlugInstall call s:install(<f-args>)
|
||||
command! -nargs=* -complete=customlist,s:names PlugUpdate call s:update(<f-args>)
|
||||
command! -nargs=0 -bang PlugClean call s:clean('<bang>' == '!')
|
||||
@@ -121,16 +123,19 @@ function! s:to_a(v)
|
||||
return type(a:v) == s:TYPE.list ? a:v : [a:v]
|
||||
endfunction
|
||||
|
||||
function! s:source(from, ...)
|
||||
for pattern in a:000
|
||||
for vim in split(globpath(a:from, pattern), '\n')
|
||||
execute 'source '.vim
|
||||
endfor
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! plug#end()
|
||||
let reload = !has('vim_starting')
|
||||
if !exists('g:plugs')
|
||||
return s:err('Call plug#begin() first')
|
||||
endif
|
||||
let keys = keys(g:plugs)
|
||||
let plugfiles = s:find_plugfiles()
|
||||
while !empty(keys)
|
||||
" No need to look for Plugfiles more than once
|
||||
let keys = keys(s:extend(keys, plugfiles))
|
||||
endwhile
|
||||
|
||||
if exists('#PlugLOD')
|
||||
augroup PlugLOD
|
||||
@@ -148,13 +153,16 @@ function! plug#end()
|
||||
for name in reverse(copy(g:plugs_order))
|
||||
let plug = g:plugs[name]
|
||||
if !has_key(plug, 'on') && !has_key(plug, 'for')
|
||||
call s:add_rtp(s:rtp(plug))
|
||||
let rtp = s:rtp(plug)
|
||||
call s:add_rtp(rtp)
|
||||
if reload
|
||||
call s:source(rtp, 'plugin/**/*.vim', 'after/plugin/**/*.vim')
|
||||
endif
|
||||
continue
|
||||
endif
|
||||
|
||||
if has_key(plug, 'on')
|
||||
let commands = s:to_a(plug.on)
|
||||
for cmd in commands
|
||||
for cmd in s:to_a(plug.on)
|
||||
if cmd =~ '^<Plug>.\+'
|
||||
if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
|
||||
for [mode, map_prefix, key_prefix] in
|
||||
@@ -173,9 +181,7 @@ function! plug#end()
|
||||
endif
|
||||
|
||||
if has_key(plug, 'for')
|
||||
for vim in split(globpath(s:rtp(plug), 'ftdetect/**/*.vim'), '\n')
|
||||
execute 'source '.vim
|
||||
endfor
|
||||
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
|
||||
for key in s:to_a(plug.for)
|
||||
if !has_key(lod, key)
|
||||
let lod[key] = []
|
||||
@@ -268,24 +274,23 @@ function! s:lod(plug, types)
|
||||
let rtp = s:rtp(a:plug)
|
||||
call s:add_rtp(rtp)
|
||||
for dir in a:types
|
||||
for vim in split(globpath(rtp, dir.'/**/*.vim'), '\n')
|
||||
execute 'source '.vim
|
||||
endfor
|
||||
call s:source(rtp, dir.'/**/*.vim')
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:lod_ft(pat, names)
|
||||
for name in a:names
|
||||
call s:lod(g:plugs[name], ['plugin', 'after'])
|
||||
call s:lod(g:plugs[name], ['plugin', 'after/plugin'])
|
||||
endfor
|
||||
call s:reorg_rtp()
|
||||
execute 'autocmd! PlugLOD FileType ' . a:pat
|
||||
silent! doautocmd filetypeplugin FileType
|
||||
silent! doautocmd filetypeindent FileType
|
||||
endfunction
|
||||
|
||||
function! s:lod_cmd(cmd, bang, l1, l2, args, name)
|
||||
execute 'delc '.a:cmd
|
||||
call s:lod(g:plugs[a:name], ['plugin', 'ftdetect', 'after'])
|
||||
call s:lod(g:plugs[a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
call s:reorg_rtp()
|
||||
execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
@@ -293,7 +298,7 @@ endfunction
|
||||
function! s:lod_map(map, name, prefix)
|
||||
execute 'unmap '.a:map
|
||||
execute 'iunmap '.a:map
|
||||
call s:lod(g:plugs[a:name], ['plugin', 'ftdetect', 'after'])
|
||||
call s:lod(g:plugs[a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
call s:reorg_rtp()
|
||||
let extra = ''
|
||||
while 1
|
||||
@@ -306,7 +311,7 @@ function! s:lod_map(map, name, prefix)
|
||||
call feedkeys(a:prefix . substitute(a:map, '^<Plug>', "\<Plug>", '') . extra)
|
||||
endfunction
|
||||
|
||||
function! s:add(force, repo, ...)
|
||||
function! s:add(repo, ...)
|
||||
if a:0 > 1
|
||||
return s:err('Invalid number of arguments (1..2)')
|
||||
endif
|
||||
@@ -314,17 +319,8 @@ function! s:add(force, repo, ...)
|
||||
try
|
||||
let repo = s:trim(a:repo)
|
||||
let name = fnamemodify(repo, ':t:s?\.git$??')
|
||||
if !a:force && has_key(g:plugs, name)
|
||||
let s:extended[name] = g:plugs[name]
|
||||
return
|
||||
endif
|
||||
|
||||
let spec = extend(s:infer_properties(name, repo),
|
||||
\ a:0 == 1 ? s:parse_options(a:1) : copy(s:base_spec))
|
||||
if !a:force
|
||||
let s:extended[name] = spec
|
||||
endif
|
||||
|
||||
\ a:0 == 1 ? s:parse_options(a:1) : s:base_spec)
|
||||
let g:plugs[name] = spec
|
||||
let g:plugs_order += [name]
|
||||
catch
|
||||
@@ -354,7 +350,7 @@ endfunction
|
||||
function! s:infer_properties(name, repo)
|
||||
let repo = a:repo
|
||||
if s:is_local_plug(repo)
|
||||
let properties = { 'dir': s:dirpath(expand(repo)), 'local': 1 }
|
||||
return { 'dir': s:dirpath(expand(repo)) }
|
||||
else
|
||||
if repo =~ ':'
|
||||
let uri = repo
|
||||
@@ -365,9 +361,8 @@ function! s:infer_properties(name, repo)
|
||||
let uri = 'https://git:@github.com/' . repo . '.git'
|
||||
endif
|
||||
let dir = s:dirpath( fnamemodify(join([g:plug_home, a:name], '/'), ':p') )
|
||||
let properties = { 'dir': dir, 'uri': uri }
|
||||
return { 'dir': dir, 'uri': uri }
|
||||
endif
|
||||
return properties
|
||||
endfunction
|
||||
|
||||
function! s:install(...)
|
||||
@@ -378,16 +373,13 @@ function! s:update(...)
|
||||
call s:update_impl(1, a:000)
|
||||
endfunction
|
||||
|
||||
function! s:apply()
|
||||
function! s:helptags()
|
||||
for spec in values(g:plugs)
|
||||
let docd = join([spec.dir, 'doc'], '/')
|
||||
if isdirectory(docd)
|
||||
silent! execute 'helptags '. join([spec.dir, 'doc'], '/')
|
||||
endif
|
||||
endfor
|
||||
runtime! plugin/*.vim
|
||||
runtime! after/*.vim
|
||||
silent! source $MYVIMRC
|
||||
endfunction
|
||||
|
||||
function! s:syntax()
|
||||
@@ -518,10 +510,11 @@ endfunction
|
||||
function! s:finish(pull)
|
||||
call append(3, '- Finishing ... ')
|
||||
redraw
|
||||
call s:apply()
|
||||
call s:syntax()
|
||||
call s:helptags()
|
||||
call plug#end()
|
||||
call setline(4, getline(4) . 'Done!')
|
||||
normal! gg
|
||||
call s:syntax()
|
||||
redraw
|
||||
let msgs = []
|
||||
if !empty(s:prev_update.errors)
|
||||
@@ -575,7 +568,6 @@ function! s:update_impl(pull, args) abort
|
||||
if !isdirectory(g:plug_home)
|
||||
call mkdir(g:plug_home, 'p')
|
||||
endif
|
||||
let len = len(g:plugs)
|
||||
let s:prev_update = { 'errors': [], 'pull': a:pull, 'new': {}, 'threads': threads }
|
||||
if has('ruby') && threads > 1
|
||||
try
|
||||
@@ -607,43 +599,10 @@ function! s:update_impl(pull, args) abort
|
||||
call s:update_serial(a:pull, todo)
|
||||
endif
|
||||
call s:do(a:pull, filter(copy(todo), 'has_key(v:val, "do")'))
|
||||
if len(g:plugs) > len
|
||||
call plug#end()
|
||||
endif
|
||||
call s:finish(a:pull)
|
||||
call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(st)))[0] . ' sec.')
|
||||
endfunction
|
||||
|
||||
function! s:find_plugfiles()
|
||||
let plugfiles = {}
|
||||
for pf in split(globpath(g:plug_home, '*/'.s:plug_file), '\n')
|
||||
let plugfiles[fnamemodify(pf, ':h:t')] = pf
|
||||
endfor
|
||||
return plugfiles
|
||||
endfunction
|
||||
|
||||
function! s:extend(names, ...)
|
||||
let s:extended = {}
|
||||
let plugfiles = a:0 > 0 ? a:1 : s:find_plugfiles()
|
||||
try
|
||||
command! -nargs=+ Plug call s:add(0, <args>)
|
||||
for name in a:names
|
||||
let spec = g:plugs[name]
|
||||
if spec.local
|
||||
let plugfile = globpath(s:rtp(spec), s:plug_file)
|
||||
if filereadable(plugfile)
|
||||
execute 'source '. s:esc(plugfile)
|
||||
endif
|
||||
elseif has_key(plugfiles, name)
|
||||
execute 'source '. s:esc(plugfiles[name])
|
||||
endif
|
||||
endfor
|
||||
finally
|
||||
command! -nargs=+ Plug call s:add(1, <args>)
|
||||
endtry
|
||||
return s:extended
|
||||
endfunction
|
||||
|
||||
function! s:update_progress(pull, cnt, bar, total)
|
||||
call setline(1, (a:pull ? 'Updating' : 'Installing').
|
||||
\ ' plugins ('.a:cnt.'/'.a:total.')')
|
||||
@@ -659,50 +618,39 @@ function! s:update_serial(pull, todo)
|
||||
let done = {}
|
||||
let bar = ''
|
||||
|
||||
while !empty(todo)
|
||||
for [name, spec] in items(todo)
|
||||
let done[name] = 1
|
||||
if isdirectory(spec.dir)
|
||||
execute 'cd '.s:esc(spec.dir)
|
||||
let [valid, msg] = s:git_valid(spec, 0, 0)
|
||||
if valid
|
||||
let result = a:pull ?
|
||||
\ s:system(
|
||||
\ printf('git checkout -q %s 2>&1 && git pull origin %s 2>&1 && git submodule update --init --recursive 2>&1',
|
||||
\ s:shellesc(spec.branch), s:shellesc(spec.branch))) : 'Already installed'
|
||||
let error = a:pull ? v:shell_error != 0 : 0
|
||||
else
|
||||
let result = msg
|
||||
let error = 1
|
||||
endif
|
||||
cd -
|
||||
for [name, spec] in items(todo)
|
||||
let done[name] = 1
|
||||
if isdirectory(spec.dir)
|
||||
execute 'cd '.s:esc(spec.dir)
|
||||
let [valid, msg] = s:git_valid(spec, 0, 0)
|
||||
if valid
|
||||
let result = a:pull ?
|
||||
\ s:system(
|
||||
\ printf('git checkout -q %s 2>&1 && git pull origin %s 2>&1 && git submodule update --init --recursive 2>&1',
|
||||
\ s:shellesc(spec.branch), s:shellesc(spec.branch))) : 'Already installed'
|
||||
let error = a:pull ? v:shell_error != 0 : 0
|
||||
else
|
||||
let result = s:system(
|
||||
\ printf('git clone --recursive %s -b %s %s 2>&1 && cd %s && git submodule update --init --recursive 2>&1',
|
||||
\ s:shellesc(spec.uri),
|
||||
\ s:shellesc(spec.branch),
|
||||
\ s:shellesc(s:trim(spec.dir)),
|
||||
\ s:shellesc(spec.dir)))
|
||||
let error = v:shell_error != 0
|
||||
if !error | let s:prev_update.new[name] = 1 | endif
|
||||
let result = msg
|
||||
let error = 1
|
||||
endif
|
||||
let bar .= error ? 'x' : '='
|
||||
if error
|
||||
call add(s:prev_update.errors, name)
|
||||
endif
|
||||
call append(3, s:format_message(!error, name, result))
|
||||
call s:update_progress(a:pull, len(done), bar, total)
|
||||
endfor
|
||||
|
||||
let extended = s:extend(keys(todo))
|
||||
if !empty(extended)
|
||||
let todo = filter(extended, '!has_key(done, v:key)')
|
||||
let total += len(todo)
|
||||
call s:update_progress(a:pull, len(done), bar, total)
|
||||
cd -
|
||||
else
|
||||
break
|
||||
let result = s:system(
|
||||
\ printf('git clone --recursive %s -b %s %s 2>&1 && cd %s && git submodule update --init --recursive 2>&1',
|
||||
\ s:shellesc(spec.uri),
|
||||
\ s:shellesc(spec.branch),
|
||||
\ s:shellesc(s:trim(spec.dir)),
|
||||
\ s:shellesc(spec.dir)))
|
||||
let error = v:shell_error != 0
|
||||
if !error | let s:prev_update.new[name] = 1 | endif
|
||||
endif
|
||||
endwhile
|
||||
let bar .= error ? 'x' : '='
|
||||
if error
|
||||
call add(s:prev_update.errors, name)
|
||||
endif
|
||||
call append(3, s:format_message(!error, name, result))
|
||||
call s:update_progress(a:pull, len(done), bar, total)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:update_parallel(pull, todo, threads)
|
||||
@@ -728,7 +676,20 @@ function! s:update_parallel(pull, todo, threads)
|
||||
%["#{arg.gsub('"', '\"')}"]
|
||||
end
|
||||
|
||||
require 'set'
|
||||
def killall pid
|
||||
pids = [pid]
|
||||
unless `which pgrep`.empty?
|
||||
children = pids
|
||||
until children.empty?
|
||||
children = children.map { |pid|
|
||||
`pgrep -P #{pid}`.lines.map { |l| l.chomp }
|
||||
}.flatten
|
||||
pids += children
|
||||
end
|
||||
end
|
||||
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
|
||||
end
|
||||
|
||||
require 'thread'
|
||||
require 'fileutils'
|
||||
require 'timeout'
|
||||
@@ -736,7 +697,7 @@ function! s:update_parallel(pull, todo, threads)
|
||||
iswin = VIM::evaluate('s:is_win').to_i == 1
|
||||
pull = VIM::evaluate('a:pull').to_i == 1
|
||||
base = VIM::evaluate('g:plug_home')
|
||||
all = VIM::evaluate('copy(a:todo)')
|
||||
all = VIM::evaluate('a:todo')
|
||||
limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
|
||||
tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1
|
||||
nthr = VIM::evaluate('a:threads').to_i
|
||||
@@ -811,17 +772,7 @@ function! s:update_parallel(pull, todo, threads)
|
||||
[$? == 0, data.chomp]
|
||||
rescue Timeout::Error, Interrupt => e
|
||||
if fd && !fd.closed?
|
||||
pids = [fd.pid]
|
||||
unless `which pgrep`.empty?
|
||||
children = pids
|
||||
until children.empty?
|
||||
children = children.map { |pid|
|
||||
`pgrep -P #{pid}`.lines.map { |l| l.chomp }
|
||||
}.flatten
|
||||
pids += children
|
||||
end
|
||||
end
|
||||
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
|
||||
killall fd.pid
|
||||
fd.close
|
||||
end
|
||||
if e.is_a?(Timeout::Error) && tried < tries
|
||||
@@ -859,63 +810,52 @@ function! s:update_parallel(pull, todo, threads)
|
||||
end
|
||||
} if VIM::evaluate('s:mac_gui') == 1
|
||||
|
||||
processed = Set.new
|
||||
progress = iswin ? '' : '--progress'
|
||||
until all.empty?
|
||||
names = all.keys
|
||||
processed.merge names
|
||||
[names.length, nthr].min.times do
|
||||
mtx.synchronize do
|
||||
threads << Thread.new {
|
||||
while pair = take1.call
|
||||
name = pair.first
|
||||
dir, uri, branch = pair.last.values_at *%w[dir uri branch]
|
||||
branch = esc branch
|
||||
subm = "git submodule update --init --recursive 2>&1"
|
||||
exists = File.directory? dir
|
||||
ok, result =
|
||||
if exists
|
||||
dir = esc dir
|
||||
ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil
|
||||
current_uri = data.lines.to_a.last
|
||||
if !ret
|
||||
if data =~ /^Interrupted|^Timeout/
|
||||
[false, data]
|
||||
else
|
||||
[false, [data.chomp, "PlugClean required."].join($/)]
|
||||
end
|
||||
elsif current_uri.sub(/git:@/, '') != uri.sub(/git:@/, '')
|
||||
[false, ["Invalid URI: #{current_uri}",
|
||||
"Expected: #{uri}",
|
||||
"PlugClean required."].join($/)]
|
||||
[all.length, nthr].min.times do
|
||||
mtx.synchronize do
|
||||
threads << Thread.new {
|
||||
while pair = take1.call
|
||||
name = pair.first
|
||||
dir, uri, branch = pair.last.values_at *%w[dir uri branch]
|
||||
branch = esc branch
|
||||
subm = "git submodule update --init --recursive 2>&1"
|
||||
exists = File.directory? dir
|
||||
ok, result =
|
||||
if exists
|
||||
dir = esc dir
|
||||
ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil
|
||||
current_uri = data.lines.to_a.last
|
||||
if !ret
|
||||
if data =~ /^Interrupted|^Timeout/
|
||||
[false, data]
|
||||
else
|
||||
if pull
|
||||
log.call name, 'Updating ...', :update
|
||||
bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && (git pull origin #{branch} #{progress} 2>&1 && #{subm})", name, :update
|
||||
else
|
||||
[true, skip]
|
||||
end
|
||||
[false, [data.chomp, "PlugClean required."].join($/)]
|
||||
end
|
||||
elsif current_uri.sub(/git:@/, '') != uri.sub(/git:@/, '')
|
||||
[false, ["Invalid URI: #{current_uri}",
|
||||
"Expected: #{uri}",
|
||||
"PlugClean required."].join($/)]
|
||||
else
|
||||
d = esc dir.sub(%r{[\\/]+$}, '')
|
||||
log.call name, 'Installing ...', :install
|
||||
bt.call "(git clone #{progress} --recursive #{uri} -b #{branch} #{d} 2>&1 && cd #{esc dir} && #{subm})", name, :install
|
||||
if pull
|
||||
log.call name, 'Updating ...', :update
|
||||
bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && (git pull origin #{branch} #{progress} 2>&1 && #{subm})", name, :update
|
||||
else
|
||||
[true, skip]
|
||||
end
|
||||
end
|
||||
mtx.synchronize { VIM::command("let s:prev_update.new['#{name}'] = 1") } if !exists && ok
|
||||
log.call name, result, ok
|
||||
end
|
||||
} if running
|
||||
end
|
||||
else
|
||||
d = esc dir.sub(%r{[\\/]+$}, '')
|
||||
log.call name, 'Installing ...', :install
|
||||
bt.call "(git clone #{progress} --recursive #{uri} -b #{branch} #{d} 2>&1 && cd #{esc dir} && #{subm})", name, :install
|
||||
end
|
||||
mtx.synchronize { VIM::command("let s:prev_update.new['#{name}'] = 1") } if !exists && ok
|
||||
log.call name, result, ok
|
||||
end
|
||||
} if running
|
||||
end
|
||||
threads.each { |t| t.join rescue nil }
|
||||
mtx.synchronize { threads.clear }
|
||||
extended = Hash[(VIM::evaluate("s:extend(#{names.inspect})") || {}).reject { |k, _|
|
||||
processed.include? k
|
||||
}]
|
||||
tot += extended.length
|
||||
all.merge!(extended)
|
||||
logh.call
|
||||
end
|
||||
threads.each { |t| t.join rescue nil }
|
||||
logh.call
|
||||
refresh.kill if refresh
|
||||
watcher.kill
|
||||
EOF
|
||||
@@ -1094,7 +1034,6 @@ endfunction
|
||||
function! s:upgrade_specs()
|
||||
for spec in values(g:plugs)
|
||||
let spec.frozen = get(spec, 'frozen', 0)
|
||||
let spec.local = get(spec, 'local', 0)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
|
||||
17
test/run
17
test/run
@@ -14,6 +14,23 @@ if [ ! -d fzf-staged ]; then
|
||||
git clone https://github.com/junegunn/fzf.git fzf-staged
|
||||
fi
|
||||
|
||||
make_dirs() {
|
||||
mkdir -p "$1"
|
||||
cd "$1"
|
||||
mkdir -p autoload colors ftdetect ftplugin indent plugin syntax
|
||||
for d in *; do
|
||||
cat > $d/xxx.vim << EOF
|
||||
" echom expand('<sfile>')
|
||||
let g:xxx = get(g:, 'xxx', [])
|
||||
call add(g:xxx, '${1:4}/$d')
|
||||
EOF
|
||||
done
|
||||
cd - > /dev/null
|
||||
}
|
||||
|
||||
make_dirs xxx/
|
||||
make_dirs xxx/after
|
||||
|
||||
cat > /tmp/mini-vimrc << VIMRC
|
||||
set rtp+=vader.vim
|
||||
source $PLUG_SRC
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Execute (Initialize test environment):
|
||||
Save &rtp, g:plugs, g:plug_home, $MYVIMRC
|
||||
Save &rtp, g:plugs, g:plug_home
|
||||
|
||||
let first_rtp = split(&rtp, ',')[0]
|
||||
let last_rtp = split(&rtp, ',')[-1]
|
||||
@@ -33,11 +33,6 @@ Execute (Initialize test environment):
|
||||
endfunction
|
||||
command! -nargs=+ -bang AssertExpect call AssertExpect('<bang>' == '!', <args>)
|
||||
|
||||
let g:vimrc_reloaded = 0
|
||||
let vimrc = tempname()
|
||||
call writefile(['let g:vimrc_reloaded += 1'], vimrc)
|
||||
let $MYVIMRC = vimrc
|
||||
|
||||
Execute (plug#end() before plug#begin() should fail):
|
||||
redir => out
|
||||
AssertEqual 0, plug#end()
|
||||
@@ -133,7 +128,6 @@ Execute (Yet, plugins are not available):
|
||||
|
||||
Execute (PlugInstall):
|
||||
PlugInstall
|
||||
AssertEqual 1, g:vimrc_reloaded
|
||||
q
|
||||
|
||||
Execute (Plugin available after installation):
|
||||
@@ -167,7 +161,6 @@ Expect:
|
||||
Execute (PlugUpdate to set the right branch):
|
||||
PlugUpdate
|
||||
call PlugStatusSorted()
|
||||
AssertEqual 2, g:vimrc_reloaded
|
||||
|
||||
Expect:
|
||||
- goyo.vim: OK
|
||||
@@ -254,7 +247,6 @@ Execute (PlugClean! to remove vim-emoji):
|
||||
Execute (PlugUpdate to install both again):
|
||||
PlugUpdate
|
||||
AssertExpect '^- [^:]*:', 2
|
||||
AssertEqual 3, g:vimrc_reloaded
|
||||
Assert !empty(globpath(&rtp, 'colors/seoul256.vim')), 'seoul256.vim should be found'
|
||||
Assert !empty(globpath(&rtp, 'autoload/emoji.vim')), 'vim-emoji should be found'
|
||||
q
|
||||
@@ -262,7 +254,6 @@ Execute (PlugUpdate to install both again):
|
||||
Execute (PlugUpdate only to find out plugins are up-to-date, D key to check):
|
||||
PlugUpdate
|
||||
AssertExpect 'Already up-to-date', 2
|
||||
AssertEqual 4, g:vimrc_reloaded
|
||||
normal D
|
||||
AssertEqual 'No updates.', getline(1)
|
||||
q
|
||||
@@ -357,7 +348,8 @@ Execute (Trying to execute on-demand commands when plugin is not installed):
|
||||
|
||||
Execute (New set of plugins):
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-fnr' " Depends on vim-pseudocl
|
||||
Plug 'junegunn/vim-fnr'
|
||||
Plug 'junegunn/vim-pseudocl'
|
||||
Plug 'junegunn/vim-easy-align', { 'on': 'EasyAlign' }
|
||||
Plug 'junegunn/vim-redis', { 'for': 'redis' }
|
||||
call plug#end()
|
||||
@@ -368,24 +360,29 @@ Execute (Check commands):
|
||||
|
||||
Execute (Partial PlugInstall):
|
||||
PlugInstall vim-fnr vim-easy-align
|
||||
AssertExpect 'vim-pseudocl', 1
|
||||
PlugInstall vim-fnr vim-easy-align 1
|
||||
AssertExpect 'vim-pseudocl', 1
|
||||
AssertExpect 'vim-fnr', 1
|
||||
q
|
||||
|
||||
Execute (Check dependent plugin):
|
||||
Assert &rtp =~ 'pseudocl', &rtp
|
||||
PlugInstall vim-fnr vim-easy-align 1
|
||||
AssertExpect 'vim-fnr', 1
|
||||
AssertExpect 'vim-easy-align', 1
|
||||
AssertEqual first_rtp, split(&rtp, ',')[0]
|
||||
AssertEqual last_rtp, split(&rtp, ',')[-1]
|
||||
q
|
||||
|
||||
Given (Unaligned code):
|
||||
a=1
|
||||
aa=2
|
||||
|
||||
Execute (Check installed plugins):
|
||||
if has('vim_starting')
|
||||
Log 'Vader is run from commandline'
|
||||
runtime! plugin/**/*.vim
|
||||
endif
|
||||
Assert exists(':FNR'), 'FNR command should be found'
|
||||
Assert exists(':EasyAlign'), 'EasyAlign command should be found'
|
||||
Assert !exists(':RedisExecute'), 'RedisExecute command still should not be found'
|
||||
|
||||
Assert exists(':EasyAlign'), 'EasyAlign command should be found'
|
||||
%EasyAlign=
|
||||
|
||||
Expect (Aligned code):
|
||||
@@ -668,6 +665,7 @@ Execute (Using Funcref):
|
||||
Execute (Using custom dir):
|
||||
Assert isdirectory(g:plugs['vim-easy-align'].dir)
|
||||
|
||||
call system('rm -rf '.$TMPDIR.'easy-align')
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align', { 'dir': $TMPDIR.'easy-align' }
|
||||
call plug#end()
|
||||
@@ -681,19 +679,64 @@ Execute (Using custom dir):
|
||||
q
|
||||
Assert isdirectory(g:plugs['vim-easy-align'].dir)
|
||||
|
||||
Execute (Cleanup):
|
||||
call system('rm -rf '.temp_plugged)
|
||||
call rename('fzf', 'fzf-staged')
|
||||
**********************************************************************
|
||||
~ On-demand loading load order
|
||||
**********************************************************************
|
||||
Before (Clear global vars):
|
||||
let g:xxx = []
|
||||
set rtp-=$PWD/xxx/
|
||||
set rtp-=$PWD/xxx/after
|
||||
|
||||
unlet g:plugs
|
||||
unlet g:plug_home
|
||||
unlet g:vimrc_reloaded
|
||||
unlet temp_plugged vader plug basertp save_rtp repo lnum fzf out
|
||||
delf PlugStatusSorted
|
||||
delf AssertExpect
|
||||
delf PlugUpdated
|
||||
delc AssertExpect
|
||||
unmap /
|
||||
unmap ?
|
||||
Execute (Immediate loading):
|
||||
call plug#begin()
|
||||
Plug '$PWD/xxx'
|
||||
call plug#end()
|
||||
|
||||
" FIXME:
|
||||
" Different result when Vader is run from commandline with `-c` option
|
||||
Log g:xxx
|
||||
if has('vim_starting')
|
||||
AssertEqual ['/ftdetect', 'after/ftdetect'], g:xxx
|
||||
else
|
||||
AssertEqual ['/plugin', 'after/plugin', '/ftdetect', 'after/ftdetect'], g:xxx
|
||||
endif
|
||||
|
||||
Execute (Command-based on-demand loading):
|
||||
call plug#begin()
|
||||
Plug '$PWD/xxx', { 'on': 'XXX' }
|
||||
call plug#end()
|
||||
|
||||
AssertEqual [], g:xxx
|
||||
|
||||
silent! XXX
|
||||
AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin'], g:xxx
|
||||
|
||||
setf xxx
|
||||
AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
|
||||
|
||||
Execute (Filetype-based on-demand loading):
|
||||
call plug#begin()
|
||||
Plug '$PWD/xxx', { 'for': 'xxx' }
|
||||
call plug#end()
|
||||
|
||||
AssertEqual ['/ftdetect', 'after/ftdetect'], g:xxx
|
||||
|
||||
setf xxx
|
||||
AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
|
||||
|
||||
Before:
|
||||
Execute (Cleanup):
|
||||
silent! call system('rm -rf '.temp_plugged)
|
||||
silent! call rename('fzf', 'fzf-staged')
|
||||
silent! unlet g:plugs
|
||||
silent! unlet g:plug_home
|
||||
silent! unlet temp_plugged vader plug basertp save_rtp repo lnum fzf out
|
||||
silent! delf PlugStatusSorted
|
||||
silent! delf AssertExpect
|
||||
silent! delf PlugUpdated
|
||||
silent! delc AssertExpect
|
||||
silent! unmap /
|
||||
silent! unmap ?
|
||||
|
||||
Restore
|
||||
|
||||
|
||||
Reference in New Issue
Block a user