mirror of
https://github.com/junegunn/vim-plug.git
synced 2025-12-07 17:44:25 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5b2c03d3a8 | ||
|
|
0b31be49cf | ||
|
|
74fa6ab9df | ||
|
|
0d7e20c984 | ||
|
|
e2714fb56e | ||
|
|
3b83a22ea4 | ||
|
|
cd418369bc | ||
|
|
279a334c8b | ||
|
|
9132e9d50d | ||
|
|
3323163e04 | ||
|
|
e4671eaf9e | ||
|
|
9afa356fb3 | ||
|
|
e04f696682 | ||
|
|
4cb5fd04a6 | ||
|
|
c16743e8fc | ||
|
|
46a6e8441f | ||
|
|
466d1839b3 |
58
README.md
58
README.md
@@ -37,28 +37,28 @@ Edit your .vimrc
|
||||
```vim
|
||||
call plug#begin('~/.vim/plugged')
|
||||
|
||||
" Make sure you use single quotes
|
||||
Plug 'junegunn/seoul256.vim'
|
||||
Plug 'junegunn/vim-easy-align'
|
||||
|
||||
" On-demand loading
|
||||
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
|
||||
Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
|
||||
" Plug 'user/repo1', 'branch_or_tag'
|
||||
" Plug 'user/repo2', { 'rtp': 'vim/plugin/dir', 'branch': 'devel' }
|
||||
" Plug 'git@github.com:junegunn/vim-github-dashboard.git'
|
||||
" ...
|
||||
|
||||
" Using git URL
|
||||
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'
|
||||
|
||||
call plug#end()
|
||||
```
|
||||
|
||||
Reload .vimrc and `:PlugInstall` to install plugins.
|
||||
|
||||
### Plugin directory
|
||||
|
||||
If you omit the path argument to `plug#begin()`, plugins are installed in
|
||||
`plugged` directory under the first path in `runtimepath` at the point when
|
||||
`plug#begin()` is called. This is usually `~/.vim/plugged` (or
|
||||
`$HOME/vimfiles/plugged` on Windows) given that you didn't touch runtimepath
|
||||
before the call.
|
||||
|
||||
### Commands
|
||||
|
||||
| Command | Description |
|
||||
@@ -70,17 +70,29 @@ before the call.
|
||||
| PlugStatus | Check the status of plugins |
|
||||
| PlugDiff | See the updated changes from the previous PlugUpdate |
|
||||
|
||||
### `Plug` options
|
||||
|
||||
| Option | Description |
|
||||
| -------------- | -------------------------------------------------------------------- |
|
||||
| `branch`/`tag` | Branch or tag of the repository to use |
|
||||
| `rtp` | Subdirectory that contains Vim plugin |
|
||||
| `on` | On-demand loading: Commands or <Plug>-mappings |
|
||||
| `for` | On-demand loading: File types |
|
||||
| `frozen` | Do not install/update plugin unless explicitly given as the argument |
|
||||
|
||||
### Options for parallel installer
|
||||
|
||||
| Flag | Default | Description |
|
||||
| ---------------- | ------- | --------------------------------- |
|
||||
| `g:plug_threads` | 16 | Default number of threads to use |
|
||||
| `g:plug_timeout` | 60 | Time limit of each task in seconds |
|
||||
| Flag | Default | Description |
|
||||
| ---------------- | ------- | ------------------------------------ |
|
||||
| `g:plug_threads` | 16 | Default number of threads to use |
|
||||
| `g:plug_timeout` | 60 | Time limit of each task in seconds |
|
||||
| `g:plug_retries` | 2 | Number of retries in case of timeout |
|
||||
|
||||
### Keybindings
|
||||
|
||||
- `D` - `PlugDiff`
|
||||
- `S` - `PlugStatus`
|
||||
- `R` - Retry failed update or installation tasks
|
||||
- `q` - Close the window
|
||||
|
||||
### Example: A small [sensible](https://github.com/tpope/vim-sensible) Vim configuration
|
||||
@@ -173,17 +185,7 @@ it as "unstable" or "in development", and always use its latest revision.
|
||||
If you really must choose a certain untagged revision, consider forking the
|
||||
repository.
|
||||
|
||||
### Regarding feature request
|
||||
### License
|
||||
|
||||
You may submit a request for a new feature by [creating an
|
||||
issue](https://github.com/junegunn/vim-plug/issues). However, please be minded
|
||||
that this is an opinionated software and I want to keep the feature set as small
|
||||
as possible. So I may not agree with you on the necessity of the suggested
|
||||
feature. If that happens, I suggest the following options.
|
||||
|
||||
1. Check out [Vundle](https://github.com/gmarik/vundle) or
|
||||
[NeoBundle](https://github.com/Shougo/neobundle.vim).
|
||||
They offer broader feature sets.
|
||||
2. Create a fork of this project and let it be your own plugin manager.
|
||||
There's no need for us to have a single canonical branch.
|
||||
MIT
|
||||
|
||||
|
||||
205
plug.vim
205
plug.vim
@@ -58,6 +58,7 @@ 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')
|
||||
|
||||
@@ -175,6 +176,7 @@ function! plug#end()
|
||||
\ key, string(key), string(reverse(names)))
|
||||
augroup END
|
||||
endfor
|
||||
call s:reorg_rtp()
|
||||
filetype plugin indent on
|
||||
syntax on
|
||||
endfunction
|
||||
@@ -218,6 +220,17 @@ function! s:add_rtp(rtp)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:reorg_rtp()
|
||||
if !empty(s:first_rtp)
|
||||
execute 'set rtp-='.s:first_rtp
|
||||
execute 'set rtp^='.s:first_rtp
|
||||
endif
|
||||
if s:last_rtp !=# s:first_rtp
|
||||
execute 'set rtp-='.s:last_rtp
|
||||
execute 'set rtp+='.s:last_rtp
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:lod(plug, types)
|
||||
let rtp = s:rtp(a:plug)
|
||||
call s:add_rtp(rtp)
|
||||
@@ -232,6 +245,7 @@ function! s:lod_ft(pat, names)
|
||||
for name in a:names
|
||||
call s:lod(g:plugs[name], ['plugin', 'after'])
|
||||
endfor
|
||||
call s:reorg_rtp()
|
||||
execute 'autocmd! PlugLOD FileType ' . a:pat
|
||||
silent! doautocmd filetypeplugin FileType
|
||||
endfunction
|
||||
@@ -239,6 +253,7 @@ 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:reorg_rtp()
|
||||
execute printf("%s%s%s %s", (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
|
||||
endfunction
|
||||
|
||||
@@ -246,6 +261,7 @@ 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:reorg_rtp()
|
||||
let extra = ''
|
||||
while 1
|
||||
let c = getchar(0)
|
||||
@@ -257,17 +273,19 @@ function! s:lod_map(map, name, prefix)
|
||||
call feedkeys(a:prefix . substitute(a:map, '^<Plug>', "\<Plug>", '') . extra)
|
||||
endfunction
|
||||
|
||||
function! s:add(...)
|
||||
let force = a:1
|
||||
let opts = { 'branch': 'master' }
|
||||
if a:0 == 2
|
||||
let plugin = a:2
|
||||
elseif a:0 == 3
|
||||
let plugin = a:2
|
||||
if type(a:3) == 1
|
||||
let opts.branch = a:3
|
||||
elseif type(a:3) == 4
|
||||
call extend(opts, a:3)
|
||||
function! s:add(force, ...)
|
||||
let opts = { 'branch': 'master', 'frozen': 0 }
|
||||
if a:0 == 1
|
||||
let plugin = a:1
|
||||
elseif a:0 == 2
|
||||
let plugin = a:1
|
||||
if type(a:2) == 1
|
||||
let opts.branch = a:2
|
||||
elseif type(a:2) == 4
|
||||
call extend(opts, a:2)
|
||||
if has_key(opts, 'tag')
|
||||
let opts.branch = remove(opts, 'tag')
|
||||
endif
|
||||
else
|
||||
echoerr "Invalid argument type (expected: string or dictionary)"
|
||||
return
|
||||
@@ -277,21 +295,32 @@ function! s:add(...)
|
||||
return
|
||||
endif
|
||||
|
||||
let plugin = substitute(plugin, '[/\\]*$', '', '')
|
||||
let name = substitute(split(plugin, '/')[-1], '\.git$', '', '')
|
||||
if !force && has_key(g:plugs, name) | return | endif
|
||||
|
||||
if plugin =~ ':'
|
||||
let uri = plugin
|
||||
else
|
||||
if plugin !~ '/'
|
||||
let plugin = 'vim-scripts/'. plugin
|
||||
endif
|
||||
let uri = 'https://git:@github.com/' . plugin . '.git'
|
||||
if !a:force && has_key(g:plugs, name)
|
||||
let s:extended[name] = g:plugs[name]
|
||||
return
|
||||
endif
|
||||
|
||||
if plugin[0] =~ '[/$~]' || plugin =~? '^[a-z]:'
|
||||
let spec = extend(opts, { 'dir': s:dirpath(expand(plugin)) })
|
||||
else
|
||||
if plugin =~ ':'
|
||||
let uri = plugin
|
||||
else
|
||||
if plugin !~ '/'
|
||||
let plugin = 'vim-scripts/'. plugin
|
||||
endif
|
||||
let uri = 'https://git:@github.com/' . plugin . '.git'
|
||||
endif
|
||||
let dir = s:dirpath( fnamemodify(join([g:plug_home, name], '/'), ':p') )
|
||||
let spec = extend(opts, { 'dir': dir, 'uri': uri })
|
||||
endif
|
||||
|
||||
let dir = s:dirpath( fnamemodify(join([g:plug_home, name], '/'), ':p') )
|
||||
let spec = extend(opts, { 'dir': dir, 'uri': uri })
|
||||
let g:plugs[name] = spec
|
||||
if !a:force
|
||||
let s:extended[name] = spec
|
||||
endif
|
||||
let g:plugs_order += [name]
|
||||
endfunction
|
||||
|
||||
@@ -307,7 +336,7 @@ function! s:apply()
|
||||
for spec in values(g:plugs)
|
||||
let docd = join([spec.dir, 'doc'], '/')
|
||||
if isdirectory(docd)
|
||||
execute "helptags ". join([spec.dir, 'doc'], '/')
|
||||
silent! execute "helptags ". join([spec.dir, 'doc'], '/')
|
||||
endif
|
||||
endfor
|
||||
runtime! plugin/*.vim
|
||||
@@ -374,6 +403,7 @@ function! s:prepare()
|
||||
else
|
||||
vertical topleft new
|
||||
nnoremap <silent> <buffer> q :if b:plug_preview==1<bar>pc<bar>endif<bar>q<cr>
|
||||
nnoremap <silent> <buffer> R :silent! call <SID>retry()<cr>
|
||||
nnoremap <silent> <buffer> D :PlugDiff<cr>
|
||||
nnoremap <silent> <buffer> S :PlugStatus<cr>
|
||||
nnoremap <silent> <buffer> ]] :silent! call <SID>section('')<cr>
|
||||
@@ -408,13 +438,30 @@ function! s:finish(pull)
|
||||
call setline(4, getline(4) . 'Done!')
|
||||
normal! gg
|
||||
redraw
|
||||
if a:pull
|
||||
echo "Press 'D' to see the updated changes."
|
||||
let msgs = []
|
||||
if !empty(s:prev_update.errors)
|
||||
call add(msgs, "Press 'R' to retry.")
|
||||
endif
|
||||
if a:pull
|
||||
call add(msgs, "Press 'D' to see the updated changes.")
|
||||
endif
|
||||
echo join(msgs, ' ')
|
||||
endfunction
|
||||
|
||||
function! s:retry()
|
||||
if empty(s:prev_update.errors)
|
||||
return
|
||||
endif
|
||||
call s:update_impl(s:prev_update.pull,
|
||||
\ extend(copy(s:prev_update.errors), [s:prev_update.threads]))
|
||||
endfunction
|
||||
|
||||
function! s:is_managed(name)
|
||||
return has_key(g:plugs[a:name], 'uri')
|
||||
endfunction
|
||||
|
||||
function! s:names(...)
|
||||
return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0')
|
||||
return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)')
|
||||
endfunction
|
||||
|
||||
function! s:update_impl(pull, args) abort
|
||||
@@ -422,8 +469,9 @@ function! s:update_impl(pull, args) abort
|
||||
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
|
||||
\ remove(args, -1) : get(g:, 'plug_threads', 16)
|
||||
|
||||
let todo = empty(args) ? g:plugs :
|
||||
\ filter(copy(g:plugs), 'index(args, v:key) >= 0')
|
||||
let managed = filter(copy(g:plugs), 's:is_managed(v:key)')
|
||||
let todo = empty(args) ? filter(managed, '!get(v:val, "frozen", 0)') :
|
||||
\ filter(managed, 'index(args, v:key) >= 0')
|
||||
|
||||
if empty(todo)
|
||||
echohl WarningMsg
|
||||
@@ -439,8 +487,13 @@ function! s:update_impl(pull, args) abort
|
||||
redraw
|
||||
|
||||
let len = len(g:plugs)
|
||||
let s:prev_update = { 'errors': [], 'pull': a:pull, 'threads': threads }
|
||||
if has('ruby') && threads > 1
|
||||
try
|
||||
let imd = &imd
|
||||
if s:mac_gui
|
||||
set noimd
|
||||
endif
|
||||
call s:update_parallel(a:pull, todo, threads)
|
||||
catch
|
||||
let lines = getline(4, '$')
|
||||
@@ -449,11 +502,17 @@ function! s:update_impl(pull, args) abort
|
||||
for line in lines
|
||||
let name = get(matchlist(line, '^. \([^:]\+\):'), 1, '')
|
||||
if empty(name) || !has_key(printed, name)
|
||||
let printed[name] = 1
|
||||
call append('$', line)
|
||||
if !empty(name)
|
||||
let printed[name] = 1
|
||||
if line[0] == 'x' && index(s:prev_update.errors, name) < 0
|
||||
call add(s:prev_update.errors, name)
|
||||
end
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
echoerr v:exception
|
||||
finally
|
||||
let &imd = imd
|
||||
endtry
|
||||
else
|
||||
call s:update_serial(a:pull, todo)
|
||||
@@ -465,7 +524,7 @@ function! s:update_impl(pull, args) abort
|
||||
endfunction
|
||||
|
||||
function! s:extend(names)
|
||||
let prev = copy(g:plugs)
|
||||
let s:extended = {}
|
||||
try
|
||||
command! -nargs=+ Plug call s:add(0, <args>)
|
||||
for name in a:names
|
||||
@@ -477,7 +536,7 @@ function! s:extend(names)
|
||||
finally
|
||||
command! -nargs=+ Plug call s:add(1, <args>)
|
||||
endtry
|
||||
return filter(copy(g:plugs), '!has_key(prev, v:key)')
|
||||
return s:extended
|
||||
endfunction
|
||||
|
||||
function! s:update_progress(pull, cnt, bar, total)
|
||||
@@ -512,6 +571,7 @@ function! s:update_serial(pull, todo)
|
||||
let result = msg
|
||||
let error = 1
|
||||
endif
|
||||
cd -
|
||||
else
|
||||
if !isdirectory(base)
|
||||
call mkdir(base, 'p')
|
||||
@@ -524,14 +584,17 @@ function! s:update_serial(pull, todo)
|
||||
\ s:shellesc(spec.dir)))
|
||||
let error = v:shell_error != 0
|
||||
endif
|
||||
cd -
|
||||
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
|
||||
|
||||
if !empty(s:extend(keys(todo)))
|
||||
let todo = filter(copy(g:plugs), '!has_key(done, v:key)')
|
||||
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)
|
||||
else
|
||||
@@ -565,27 +628,28 @@ function! s:update_parallel(pull, todo, threads)
|
||||
%["#{arg.gsub('"', '\"')}"]
|
||||
end
|
||||
|
||||
st = Time.now
|
||||
require 'set'
|
||||
require 'thread'
|
||||
require 'fileutils'
|
||||
require 'timeout'
|
||||
running = true
|
||||
st = Time.now
|
||||
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)')
|
||||
limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
|
||||
tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1
|
||||
nthr = VIM::evaluate('a:threads').to_i
|
||||
maxy = VIM::evaluate('winheight(".")').to_i
|
||||
cd = iswin ? 'cd /d' : 'cd'
|
||||
tot = 0
|
||||
tot = VIM::evaluate('len(a:todo)') || 0
|
||||
bar = ''
|
||||
skip = 'Already installed'
|
||||
mtx = Mutex.new
|
||||
take1 = proc { mtx.synchronize { running && all.shift } }
|
||||
logh = proc {
|
||||
cnt = $curbuf[2][1...-1].strip.length
|
||||
tot = VIM::evaluate('len(a:todo)') || tot
|
||||
cnt = bar.length
|
||||
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
|
||||
$curbuf[2] = '[' + bar.ljust(tot) + ']'
|
||||
VIM::command('normal! 2G')
|
||||
@@ -598,7 +662,10 @@ function! s:update_parallel(pull, todo, threads)
|
||||
bar += type ? '=' : 'x' unless ing
|
||||
b = case type
|
||||
when :install then '+' when :update then '*'
|
||||
when true, nil then '-' else 'x' end
|
||||
when true, nil then '-' else
|
||||
VIM::command("call add(s:prev_update.errors, '#{name}')")
|
||||
'x'
|
||||
end
|
||||
result =
|
||||
if type || type.nil?
|
||||
["#{b} #{name}: #{result.lines.to_a.last}"]
|
||||
@@ -618,11 +685,14 @@ function! s:update_parallel(pull, todo, threads)
|
||||
end
|
||||
}
|
||||
bt = proc { |cmd, name, type|
|
||||
tried = timeout = 0
|
||||
begin
|
||||
tried += 1
|
||||
timeout += limit
|
||||
fd = nil
|
||||
data = ''
|
||||
if iswin
|
||||
Timeout::timeout(limit) do
|
||||
Timeout::timeout(timeout) do
|
||||
tmp = VIM::evaluate('tempname()')
|
||||
system("#{cmd} > #{tmp}")
|
||||
data = File.read(tmp).chomp
|
||||
@@ -632,7 +702,7 @@ function! s:update_parallel(pull, todo, threads)
|
||||
fd = IO.popen(cmd).extend(PlugStream)
|
||||
first_line = true
|
||||
log_prob = 1.0 / nthr
|
||||
while line = Timeout::timeout(limit) { fd.get_line }
|
||||
while line = Timeout::timeout(timeout) { fd.get_line }
|
||||
data << line
|
||||
log.call name, line.chomp, type if name && (first_line || rand < log_prob)
|
||||
first_line = false
|
||||
@@ -655,6 +725,15 @@ function! s:update_parallel(pull, todo, threads)
|
||||
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
|
||||
fd.close
|
||||
end
|
||||
if e.is_a?(Timeout::Error) && tried < tries
|
||||
3.downto(1) do |countdown|
|
||||
s = countdown > 1 ? 's' : ''
|
||||
log.call name, "Timeout. Will retry in #{countdown} second#{s} ...", type
|
||||
sleep 1
|
||||
end
|
||||
log.call name, 'Retrying ...', type
|
||||
retry
|
||||
end
|
||||
[false, e.is_a?(Interrupt) ? "Interrupted!" : "Timeout!"]
|
||||
end
|
||||
}
|
||||
@@ -671,10 +750,21 @@ function! s:update_parallel(pull, todo, threads)
|
||||
threads.each { |t| t.join rescue nil }
|
||||
main.kill
|
||||
}
|
||||
refresh = Thread.new {
|
||||
while true
|
||||
mtx.synchronize do
|
||||
break unless running
|
||||
VIM::command('noautocmd normal! a')
|
||||
end
|
||||
sleep 0.2
|
||||
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 {
|
||||
@@ -719,9 +809,14 @@ function! s:update_parallel(pull, todo, threads)
|
||||
end
|
||||
threads.each { |t| t.join rescue nil }
|
||||
mtx.synchronize { threads.clear }
|
||||
all.merge!(VIM::evaluate("s:extend(#{names.inspect})") || {})
|
||||
extended = Hash[(VIM::evaluate("s:extend(#{names.inspect})") || {}).reject { |k, _|
|
||||
processed.include? k
|
||||
}]
|
||||
tot += extended.length
|
||||
all.merge!(extended)
|
||||
logh.call
|
||||
end
|
||||
refresh.kill if refresh
|
||||
watcher.kill
|
||||
$curbuf[1] = "Updated. Elapsed time: #{"%.6f" % (Time.now - st)} sec."
|
||||
EOF
|
||||
@@ -804,8 +899,9 @@ function! s:clean(force)
|
||||
|
||||
" List of valid directories
|
||||
let dirs = []
|
||||
let [cnt, total] = [0, len(g:plugs)]
|
||||
for spec in values(g:plugs)
|
||||
let managed = filter(copy(g:plugs), 's:is_managed(v:key)')
|
||||
let [cnt, total] = [0, len(managed)]
|
||||
for spec in values(managed)
|
||||
if s:git_valid(spec, 0, 1)[0]
|
||||
call add(dirs, spec.dir)
|
||||
endif
|
||||
@@ -906,10 +1002,18 @@ function! s:status()
|
||||
let ecnt = 0
|
||||
let [cnt, total] = [0, len(g:plugs)]
|
||||
for [name, spec] in items(g:plugs)
|
||||
if isdirectory(spec.dir)
|
||||
let [valid, msg] = s:git_valid(spec, 1, 1)
|
||||
if has_key(spec, 'uri')
|
||||
if isdirectory(spec.dir)
|
||||
let [valid, msg] = s:git_valid(spec, 1, 1)
|
||||
else
|
||||
let [valid, msg] = [0, 'Not found. Try PlugInstall.']
|
||||
endif
|
||||
else
|
||||
let [valid, msg] = [0, 'Not found. Try PlugInstall.']
|
||||
if isdirectory(spec.dir)
|
||||
let [valid, msg] = [1, 'OK']
|
||||
else
|
||||
let [valid, msg] = [0, 'Not found.']
|
||||
endif
|
||||
endif
|
||||
let cnt += 1
|
||||
let ecnt += !valid
|
||||
@@ -973,7 +1077,7 @@ function! s:diff()
|
||||
|
||||
let cnt = 0
|
||||
for [k, v] in items(g:plugs)
|
||||
if !isdirectory(v.dir)
|
||||
if !isdirectory(v.dir) || !s:is_managed(k)
|
||||
continue
|
||||
endif
|
||||
|
||||
@@ -995,6 +1099,9 @@ function! s:diff()
|
||||
normal! gg
|
||||
endfunction
|
||||
|
||||
let s:first_rtp = s:esc(get(split(&rtp, ','), 0, ''))
|
||||
let s:last_rtp = s:esc(get(split(&rtp, ','), -1, ''))
|
||||
|
||||
let &cpo = s:cpo_save
|
||||
unlet s:cpo_save
|
||||
|
||||
|
||||
8
test/run
8
test/run
@@ -9,13 +9,19 @@ if [ ! -d vader.vim ]; then
|
||||
git clone https://github.com/junegunn/vader.vim.git
|
||||
fi
|
||||
|
||||
rm -rf fzf
|
||||
if [ ! -d fzf-staged ]; then
|
||||
git clone https://github.com/junegunn/fzf.git fzf-staged
|
||||
fi
|
||||
|
||||
cat > /tmp/mini-vimrc << VIMRC
|
||||
set rtp+=vader.vim
|
||||
source $PLUG_SRC
|
||||
VIMRC
|
||||
|
||||
if [ "$1" = '!' ]; then
|
||||
/usr/local/bin/vim -Nu /tmp/mini-vimrc -c 'Vader! workflow.vader' > /dev/null
|
||||
/usr/local/bin/vim -Nu /tmp/mini-vimrc -c 'Vader! workflow.vader' > /dev/null &&
|
||||
/usr/local/bin/vim -Nu /tmp/mini-vimrc -c 'let g:plug_threads = 1 | Vader! workflow.vader' > /dev/null
|
||||
else
|
||||
/usr/local/bin/vim -Nu /tmp/mini-vimrc -c 'Vader workflow.vader'
|
||||
fi
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
Execute (Initialize test environment):
|
||||
Save &rtp, g:plugs, g:plug_home, $MYVIMRC
|
||||
|
||||
let first_rtp = split(&rtp, ',')[0]
|
||||
let last_rtp = split(&rtp, ',')[-1]
|
||||
|
||||
let vader = fnamemodify(globpath(&rtp, 'autoload/vader.vim'), ':h:h')
|
||||
let plug = fnamemodify(globpath(&rtp, 'autoload/plug.vim'), ':h:h')
|
||||
set rtp=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
|
||||
@@ -24,6 +27,12 @@ Execute (Initialize test environment):
|
||||
g/^$/d
|
||||
endfunction
|
||||
|
||||
function! AssertExpect(bang, pat, cnt)
|
||||
let op = a:bang ? '==' : '=~'
|
||||
AssertEqual a:cnt, len(filter(getline(1, '$'), "v:val ".op." '".a:pat."'"))
|
||||
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)
|
||||
@@ -68,15 +77,21 @@ Execute (Subsequent plug#begin() calls will reuse g:plug_home):
|
||||
|
||||
Execute (Test Plug command):
|
||||
" Git repo with branch
|
||||
Plug 'junegunn/seoul256.vim', 'no-t_co'
|
||||
Plug 'junegunn/seoul256.vim', 'yes-t_co'
|
||||
AssertEqual 'https://git:@github.com/junegunn/seoul256.vim.git', g:plugs['seoul256.vim'].uri
|
||||
AssertEqual join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
|
||||
AssertEqual 'yes-t_co', g:plugs['seoul256.vim'].branch
|
||||
|
||||
Plug 'junegunn/seoul256.vim', { 'branch': 'no-t_co' } " Using branch option
|
||||
AssertEqual 'no-t_co', g:plugs['seoul256.vim'].branch
|
||||
|
||||
" Git repo with tag
|
||||
Plug 'junegunn/goyo.vim', '1.5.3'
|
||||
Plug 'junegunn/goyo.vim', '1.5.2'
|
||||
AssertEqual 'https://git:@github.com/junegunn/goyo.vim.git', g:plugs['goyo.vim'].uri
|
||||
AssertEqual join([temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
|
||||
AssertEqual '1.5.2', g:plugs['goyo.vim'].branch
|
||||
|
||||
Plug 'junegunn/goyo.vim', { 'tag': '1.5.3' } " Using tag option
|
||||
AssertEqual '1.5.3', g:plugs['goyo.vim'].branch
|
||||
|
||||
" Git URI
|
||||
@@ -103,17 +118,19 @@ Execute (Plug command with dictionary option):
|
||||
|
||||
Execute (PlugStatus before installation):
|
||||
PlugStatus
|
||||
AssertEqual 4, len(filter(getline(1, line('$')), 'v:val =~ "Not found"'))
|
||||
AssertExpect 'Not found', 4
|
||||
q
|
||||
|
||||
Execute (PlugClean before installation):
|
||||
PlugClean
|
||||
AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Already clean"'))
|
||||
AssertExpect 'Already clean', 1
|
||||
q
|
||||
|
||||
Execute (plug#end() updates &rtp):
|
||||
call plug#end()
|
||||
Assert len(&rtp) > len(basertp)
|
||||
AssertEqual first_rtp, split(&rtp, ',')[0]
|
||||
AssertEqual last_rtp, split(&rtp, ',')[-1]
|
||||
|
||||
Execute (Yet, plugins are not available):
|
||||
Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
|
||||
@@ -128,12 +145,13 @@ Execute (Plugin available after installation):
|
||||
|
||||
Execute (PlugClean after installation):
|
||||
PlugClean
|
||||
AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Already clean"'))
|
||||
AssertExpect 'Already clean', 1
|
||||
q
|
||||
|
||||
Execute (PlugStatus after installation):
|
||||
PlugStatus
|
||||
AssertEqual 4, len(filter(getline(1, line('$')), 'v:val =~ "OK"'))
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'OK', 4
|
||||
q
|
||||
|
||||
Execute (Change tag of goyo.vim):
|
||||
@@ -204,8 +222,8 @@ Expect:
|
||||
Execute (PlugClean! to remove seoul256.vim):
|
||||
PlugClean!
|
||||
" Three removed, emoji left
|
||||
AssertEqual 3, len(filter(getline(1, line('$')), 'v:val =~ "^- "'))
|
||||
AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Removed"'))
|
||||
AssertExpect '^- ', 3
|
||||
AssertExpect 'Removed', 1
|
||||
Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
|
||||
Assert !empty(globpath(&rtp, 'autoload/emoji.vim'))
|
||||
q
|
||||
@@ -231,15 +249,15 @@ Expect:
|
||||
|
||||
Execute (PlugClean! to remove vim-emoji):
|
||||
PlugClean!
|
||||
AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "^- "'))
|
||||
AssertEqual 1, len(filter(getline(1, line('$')), 'v:val =~ "Removed"'))
|
||||
AssertExpect '^- ', 1
|
||||
AssertExpect 'Removed', 1
|
||||
Assert empty(globpath(&rtp, 'colors/seoul256.vim'))
|
||||
Assert empty(globpath(&rtp, 'autoload/emoji.vim'))
|
||||
q
|
||||
|
||||
Execute (PlugUpdate to install both again):
|
||||
PlugUpdate
|
||||
AssertEqual 2, len(filter(getline(1, line('$')), 'v:val =~ "^- [^:]*:"'))
|
||||
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'
|
||||
@@ -247,7 +265,7 @@ Execute (PlugUpdate to install both again):
|
||||
|
||||
Execute (PlugUpdate only to find out plugins are up-to-date, D key to check):
|
||||
PlugUpdate
|
||||
AssertEqual 2, len(filter(getline(1, line('$')), 'v:val =~ "Already up-to-date"'))
|
||||
AssertExpect 'Already up-to-date', 2
|
||||
AssertEqual 4, g:vimrc_reloaded
|
||||
normal D
|
||||
AssertEqual 'No updates.', getline(1)
|
||||
@@ -354,11 +372,15 @@ 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
|
||||
q
|
||||
|
||||
Execute (Check dependent plugin):
|
||||
Assert &rtp =~ 'pseudocl', &rtp
|
||||
AssertEqual first_rtp, split(&rtp, ',')[0]
|
||||
AssertEqual last_rtp, split(&rtp, ',')[-1]
|
||||
|
||||
Given (Unaligned code):
|
||||
a=1
|
||||
@@ -384,13 +406,186 @@ Execute (On-demand loading based on filetypes):
|
||||
set ft=redis
|
||||
Assert exists(':RedisExecute'), 'RedisExecute command is now found'
|
||||
|
||||
**********************************************************************
|
||||
~ Local (unmanaged) plugins
|
||||
**********************************************************************
|
||||
|
||||
Execute (Add unmanaged plugin):
|
||||
let fzf = fnamemodify(g:vader_file, ':h') . '/fzf'
|
||||
Log fzf
|
||||
|
||||
call plug#begin()
|
||||
Plug fzf, { 'on': 'SomeCommand' }
|
||||
call plug#end()
|
||||
|
||||
" Check uri field
|
||||
Assert !has_key(g:plugs.fzf, 'uri'), 'Should not have uri field'
|
||||
|
||||
" Check dir field
|
||||
AssertEqual fzf.'/', g:plugs.fzf.dir
|
||||
|
||||
" Trailing slashes and backslashes should be stripped
|
||||
for suffix in ['///', '/\/\/']
|
||||
call plug#begin()
|
||||
Plug fzf.suffix, { 'on': 'SomeCommand' }
|
||||
call plug#end()
|
||||
|
||||
" Check dir field
|
||||
AssertEqual fzf.'/', g:plugs.fzf.dir
|
||||
endfor
|
||||
|
||||
Execute (Plug block for following tests):
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align'
|
||||
Plug fzf, { 'on': 'SomeCommand' }
|
||||
call plug#end()
|
||||
" Remove plugins from previous tests
|
||||
PlugClean!
|
||||
|
||||
Execute (PlugInstall will only install vim-easy-align):
|
||||
PlugInstall
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'fzf', 0
|
||||
q
|
||||
|
||||
Execute (PlugUpdate will only update vim-easy-align):
|
||||
PlugUpdate
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'fzf', 0
|
||||
q
|
||||
|
||||
Execute (PlugClean should not care about unmanaged plugins):
|
||||
PlugClean
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'fzf', 0
|
||||
q
|
||||
|
||||
Execute (PlugStatus should point out that the plugin is missing):
|
||||
PlugStatus
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'x fzf', 1
|
||||
AssertExpect 'Not found', 1
|
||||
q
|
||||
|
||||
Execute (Deploy unmanaged plugin):
|
||||
Assert !exists(':FZF'), ':FZF command should not exist'
|
||||
call rename('fzf-staged', 'fzf')
|
||||
|
||||
Execute (PlugUpdate still should not care):
|
||||
PlugUpdate
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'fzf', 0
|
||||
q
|
||||
|
||||
Execute (PlugStatus with no error):
|
||||
PlugStatus
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'x fzf', 0
|
||||
AssertExpect 'Not found', 0
|
||||
q
|
||||
|
||||
Execute (Check &rtp after SomeCommand):
|
||||
Log &rtp
|
||||
Assert &rtp !~ 'fzf'
|
||||
silent! SomeCommand
|
||||
Assert &rtp =~ 'fzf'
|
||||
AssertEqual first_rtp, split(&rtp, ',')[0]
|
||||
AssertEqual last_rtp, split(&rtp, ',')[-1]
|
||||
|
||||
Execute (Common parent):
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-pseudocl'
|
||||
Plug 'junegunn/vim-fnr'
|
||||
Plug 'junegunn/vim-oblique'
|
||||
call plug#end()
|
||||
|
||||
PlugInstall
|
||||
Log getline(1, '$')
|
||||
AssertExpect! '[===]', 1
|
||||
q
|
||||
|
||||
**********************************************************************
|
||||
~ Frozen plugins
|
||||
**********************************************************************
|
||||
|
||||
Execute (Frozen plugin are not installed nor updated):
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align', { 'frozen': 1 }
|
||||
call plug#end()
|
||||
|
||||
redir => output
|
||||
silent PlugInstall
|
||||
redir END
|
||||
Assert output =~ 'No plugin to install'
|
||||
|
||||
redir => output
|
||||
silent PlugUpdate
|
||||
redir END
|
||||
Assert output =~ 'No plugin to update'
|
||||
|
||||
Execute (But you can still install it if the name is given as the argument):
|
||||
PlugInstall vim-easy-align
|
||||
Log getline(1, '$')
|
||||
AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
|
||||
q
|
||||
|
||||
PlugUpdate vim-easy-align
|
||||
Log getline(1, '$')
|
||||
AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
|
||||
q
|
||||
|
||||
**********************************************************************
|
||||
~ Retry
|
||||
**********************************************************************
|
||||
|
||||
Execute (Retry failed tasks):
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align'
|
||||
Plug 'junegunn/aaaaaaaaaaaaaa'
|
||||
call plug#end()
|
||||
|
||||
PlugInstall
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'x aaa', 1
|
||||
AssertExpect '- vim-easy-align', 1
|
||||
normal R
|
||||
Log getline(1, '$')
|
||||
AssertExpect 'x aaa', 1
|
||||
AssertExpect '- vim-easy-align', 0
|
||||
AssertExpect! '[x]', 1
|
||||
q
|
||||
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align'
|
||||
Plug 'junegunn/aaaaaaaaaaaaaa'
|
||||
Plug 'junegunn/bbbbbbbbbbbbbb'
|
||||
Plug 'junegunn/cccccccccccccc'
|
||||
call plug#end()
|
||||
|
||||
" Ruby installer
|
||||
PlugUpdate
|
||||
normal R
|
||||
AssertExpect '- vim-easy-align', 0
|
||||
AssertExpect! '[xxx]', 1
|
||||
q
|
||||
|
||||
" Vim installer
|
||||
PlugUpdate 1
|
||||
normal R
|
||||
AssertExpect '- vim-easy-align', 0
|
||||
AssertExpect! '[xxx]', 1
|
||||
q
|
||||
|
||||
Execute (Cleanup):
|
||||
call system('rm -rf '.temp_plugged)
|
||||
call rename('fzf', 'fzf-staged')
|
||||
|
||||
unlet g:plugs
|
||||
unlet g:plug_home
|
||||
unlet g:vimrc_reloaded
|
||||
unlet temp_plugged vader plug basertp save_rtp repo lnum
|
||||
unlet temp_plugged vader plug basertp save_rtp repo lnum fzf
|
||||
delf PlugStatusSorted
|
||||
delf AssertExpect
|
||||
delc AssertExpect
|
||||
|
||||
Restore
|
||||
|
||||
Reference in New Issue
Block a user