mirror of
https://github.com/junegunn/vim-plug.git
synced 2025-12-07 09:34:25 +08:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
425ef39db2 | ||
|
|
bd2cb9d2de | ||
|
|
0263370bd1 | ||
|
|
4b3fbd1592 |
18
README.md
18
README.md
@@ -74,15 +74,15 @@ Reload .vimrc and `:PlugInstall` to install plugins.
|
||||
|
||||
### `Plug` options
|
||||
|
||||
| Option | Description |
|
||||
| -------------- | -------------------------------------------------------------------- |
|
||||
| `branch`/`tag` | Branch or tag of the repository to use |
|
||||
| `rtp` | Subdirectory that contains Vim plugin |
|
||||
| `dir` | Custom directory for the plugin |
|
||||
| `do` | Post-update hook (string or funcref) |
|
||||
| `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 |
|
||||
| Option | Description |
|
||||
| -------------- | ------------------------------------------------ |
|
||||
| `branch`/`tag` | Branch or tag of the repository to use |
|
||||
| `rtp` | Subdirectory that contains Vim plugin |
|
||||
| `dir` | Custom directory for the plugin |
|
||||
| `do` | Post-update hook (string or funcref) |
|
||||
| `on` | On-demand loading: Commands or `<Plug>`-mappings |
|
||||
| `for` | On-demand loading: File types |
|
||||
| `frozen` | Do not update unless explicitly specified |
|
||||
|
||||
### Global options
|
||||
|
||||
|
||||
34
plug.vim
34
plug.vim
@@ -289,9 +289,10 @@ function! s:reorg_rtp()
|
||||
let s:middle = get(s:, 'middle', &rtp)
|
||||
let rtps = map(s:loaded_names(), 's:rtp(g:plugs[v:val])')
|
||||
let afters = filter(map(copy(rtps), 'globpath(v:val, "after")'), 'isdirectory(v:val)')
|
||||
let &rtp = join(map(rtps, 's:escrtp(v:val)'), ',')
|
||||
\ . substitute(','.s:middle.',', '^,,$', ',', '')
|
||||
let rtp = join(map(rtps, 's:escrtp(v:val)'), ',')
|
||||
\ . ','.s:middle.','
|
||||
\ . join(map(afters, 's:escrtp(v:val)'), ',')
|
||||
let &rtp = substitute(substitute(rtp, ',,*', ',', 'g'), '^,\|,$', '', 'g')
|
||||
let s:prtp = &rtp
|
||||
|
||||
if !empty(s:first_rtp)
|
||||
@@ -315,7 +316,7 @@ function! plug#load(...)
|
||||
for name in a:000
|
||||
call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
|
||||
endfor
|
||||
silent! doautocmd BufRead
|
||||
doautocmd BufRead
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
@@ -336,8 +337,8 @@ endfunction
|
||||
function! s:lod_ft(pat, names)
|
||||
call s:lod(a:names, ['plugin', 'after/plugin'])
|
||||
execute 'autocmd! PlugLOD FileType' a:pat
|
||||
silent! doautocmd filetypeplugin FileType
|
||||
silent! doautocmd filetypeindent FileType
|
||||
doautocmd filetypeplugin FileType
|
||||
doautocmd filetypeindent FileType
|
||||
endfunction
|
||||
|
||||
function! s:lod_cmd(cmd, bang, l1, l2, args, name)
|
||||
@@ -613,6 +614,11 @@ function! s:do(pull, force, todo)
|
||||
endfunction
|
||||
|
||||
function! s:finish(pull)
|
||||
let new_frozen = len(filter(keys(s:update.new), 'g:plugs[v:val].frozen'))
|
||||
if new_frozen
|
||||
let s = new_frozen > 1 ? 's' : ''
|
||||
call append(3, printf('- Installed %d frozen plugin%s', new_frozen, s))
|
||||
endif
|
||||
call append(3, '- Finishing ... ')
|
||||
redraw
|
||||
call plug#helptags()
|
||||
@@ -652,7 +658,7 @@ function! s:update_impl(pull, force, args) abort
|
||||
\ remove(args, -1) : get(g:, 'plug_threads', 16)
|
||||
|
||||
let managed = filter(copy(g:plugs), 's:is_managed(v:key)')
|
||||
let todo = empty(args) ? filter(managed, '!v:val.frozen') :
|
||||
let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') :
|
||||
\ filter(managed, 'index(args, v:key) >= 0')
|
||||
|
||||
if empty(todo)
|
||||
@@ -1268,12 +1274,7 @@ function! s:upgrade()
|
||||
throw get(s:lines(output), -1, v:shell_error)
|
||||
endif
|
||||
elseif has('ruby')
|
||||
ruby << EOF
|
||||
require 'open-uri'
|
||||
File.open(VIM::evaluate('new'), 'w') do |f|
|
||||
f << open(VIM::evaluate('s:plug_src')).read
|
||||
end
|
||||
EOF
|
||||
call s:upgrade_using_ruby(new)
|
||||
else
|
||||
return s:err('curl executable or ruby support not found')
|
||||
endif
|
||||
@@ -1294,6 +1295,15 @@ EOF
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:upgrade_using_ruby(new)
|
||||
ruby << EOF
|
||||
require 'open-uri'
|
||||
File.open(VIM::evaluate('a:new'), 'w') do |f|
|
||||
f << open(VIM::evaluate('s:plug_src')).read
|
||||
end
|
||||
EOF
|
||||
endfunction
|
||||
|
||||
function! s:upgrade_specs()
|
||||
for spec in values(g:plugs)
|
||||
let spec.frozen = get(spec, 'frozen', 0)
|
||||
|
||||
5
test/fixtures/.gitignore
vendored
Normal file
5
test/fixtures/.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
fzf*
|
||||
xxx
|
||||
yyy
|
||||
z1
|
||||
z2
|
||||
1
test/fixtures/ftplugin-msg/ftplugin/c.vim
vendored
Normal file
1
test/fixtures/ftplugin-msg/ftplugin/c.vim
vendored
Normal file
@@ -0,0 +1 @@
|
||||
echomsg 'ftplugin'
|
||||
16
test/run
16
test/run
@@ -5,18 +5,20 @@ cd ..
|
||||
PLUG_SRC=$(pwd)/plug.vim
|
||||
cd - > /dev/null
|
||||
|
||||
export PLUG_FIXTURES=$(pwd)/fixtures
|
||||
|
||||
if [ ! -d vader.vim ]; then
|
||||
git clone https://github.com/junegunn/vader.vim.git
|
||||
fi
|
||||
|
||||
rm -rf fzf
|
||||
rm -rf $PLUG_FIXTURES/fzf
|
||||
if [ ! -d fzf-staged ]; then
|
||||
git clone https://github.com/junegunn/fzf.git fzf-staged
|
||||
git clone https://github.com/junegunn/fzf.git $PLUG_FIXTURES/fzf-staged
|
||||
fi
|
||||
|
||||
make_dirs() {
|
||||
mkdir -p "temp/$1"
|
||||
cd "temp/$1"
|
||||
mkdir -p "$PLUG_FIXTURES/$1"
|
||||
cd "$PLUG_FIXTURES/$1"
|
||||
mkdir -p autoload colors ftdetect ftplugin indent plugin syntax
|
||||
for d in *; do
|
||||
[ -d $d ] || continue
|
||||
@@ -33,12 +35,12 @@ EOF
|
||||
}
|
||||
|
||||
init() {
|
||||
rm -rf temp/{xxx,yyy,z1,z2}
|
||||
rm -rf $PLUG_FIXTURES/{xxx,yyy,z1,z2}
|
||||
|
||||
make_dirs xxx/ xxx
|
||||
make_dirs xxx/after xxx
|
||||
mkdir -p temp/xxx/doc
|
||||
cat > temp/xxx/doc/xxx.txt << DOC
|
||||
mkdir -p $PLUG_FIXTURES/xxx/doc
|
||||
cat > $PLUG_FIXTURES/xxx/doc/xxx.txt << DOC
|
||||
hello *xxx*
|
||||
DOC
|
||||
|
||||
|
||||
@@ -421,7 +421,7 @@ Execute (On-demand loading based on filetypes):
|
||||
**********************************************************************
|
||||
|
||||
Execute (Add unmanaged plugin):
|
||||
let fzf = fnamemodify(g:vader_file, ':h') . '/fzf'
|
||||
let fzf = expand('$PLUG_FIXTURES/fzf')
|
||||
Log fzf
|
||||
|
||||
call plug#begin()
|
||||
@@ -479,7 +479,7 @@ Execute (PlugStatus should point out that the plugin is missing):
|
||||
|
||||
Execute (Deploy unmanaged plugin):
|
||||
Assert !exists(':FZF'), ':FZF command should not exist'
|
||||
call rename('fzf-staged', 'fzf')
|
||||
call rename(expand('$PLUG_FIXTURES/fzf-staged'), fzf)
|
||||
|
||||
Execute (PlugUpdate still should not care):
|
||||
PlugUpdate
|
||||
@@ -517,12 +517,37 @@ Execute (Common parent):
|
||||
**********************************************************************
|
||||
~ Frozen plugins
|
||||
**********************************************************************
|
||||
- We've decided to install plugins that are frozen: see #113
|
||||
Execute (Frozen plugin are not ~~installed nor~~ updated):
|
||||
" Remove plugins
|
||||
call plug#begin()
|
||||
call plug#end()
|
||||
PlugClean!
|
||||
q
|
||||
|
||||
Execute (Frozen plugin are not installed nor updated):
|
||||
" vim-easy-align is not found, so it will be installed even though it's frozen
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align', { 'frozen': 1 }
|
||||
call plug#end()
|
||||
PlugInstall
|
||||
AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
|
||||
q
|
||||
|
||||
" Remove plugins again
|
||||
call plug#begin()
|
||||
call plug#end()
|
||||
PlugClean!
|
||||
q
|
||||
|
||||
" PlugUpdate will do the same
|
||||
call plug#begin()
|
||||
Plug 'junegunn/vim-easy-align', { 'frozen': 1 }
|
||||
call plug#end()
|
||||
PlugInstall
|
||||
AssertEqual 1, len(filter(getline(1, '$'), 'v:val =~ "vim-easy-align"'))
|
||||
q
|
||||
|
||||
" Since vim-easy-align already exists, PlugInstall or PlugUpdate will skip it
|
||||
redir => out
|
||||
silent PlugInstall
|
||||
redir END
|
||||
@@ -732,12 +757,12 @@ Execute (Using custom dir):
|
||||
**********************************************************************
|
||||
Before (Clear global vars):
|
||||
let g:xxx = []
|
||||
set rtp-=$PWD/temp/xxx/
|
||||
set rtp-=$PWD/temp/xxx/after
|
||||
set rtp-=$PLUG_FIXTURES/xxx/
|
||||
set rtp-=$PLUG_FIXTURES/xxx/after
|
||||
|
||||
Execute (Immediate loading):
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/xxx'
|
||||
Plug '$PLUG_FIXTURES/xxx'
|
||||
call plug#end()
|
||||
|
||||
" FIXME:
|
||||
@@ -751,7 +776,7 @@ Execute (Immediate loading):
|
||||
|
||||
Execute (Command-based on-demand loading):
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/xxx', { 'on': 'XXX' }
|
||||
Plug '$PLUG_FIXTURES/xxx', { 'on': 'XXX' }
|
||||
call plug#end()
|
||||
|
||||
AssertEqual [], g:xxx
|
||||
@@ -764,7 +789,7 @@ Execute (Command-based on-demand loading):
|
||||
|
||||
Execute (Filetype-based on-demand loading):
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/xxx', { 'for': 'xxx' }
|
||||
Plug '$PLUG_FIXTURES/xxx', { 'for': 'xxx' }
|
||||
call plug#end()
|
||||
|
||||
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect'], g:xxx
|
||||
@@ -779,10 +804,10 @@ Before:
|
||||
**********************************************************************
|
||||
|
||||
Execute (plug#helptags):
|
||||
silent! call delete(expand('$PWD/temp/xxx/doc/tags'))
|
||||
Assert !filereadable(expand('$PWD/temp/xxx/doc/tags'))
|
||||
silent! call delete(expand('$PLUG_FIXTURES/xxx/doc/tags'))
|
||||
Assert !filereadable(expand('$PLUG_FIXTURES/xxx/doc/tags'))
|
||||
AssertEqual 1, plug#helptags()
|
||||
Assert filereadable(expand('$PWD/temp/xxx/doc/tags'))
|
||||
Assert filereadable(expand('$PLUG_FIXTURES/xxx/doc/tags'))
|
||||
|
||||
**********************************************************************
|
||||
~ Manual loading
|
||||
@@ -823,7 +848,7 @@ Execute (PlugStatus should not contain (not loaded)):
|
||||
|
||||
Execute (Load plugin from PlugStatus screen with L key in normal mode):
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/yyy', { 'on': [] }
|
||||
Plug '$PLUG_FIXTURES/yyy', { 'on': [] }
|
||||
call plug#end()
|
||||
|
||||
PlugStatus
|
||||
@@ -837,8 +862,8 @@ Execute (Load plugin from PlugStatus screen with L key in normal mode):
|
||||
|
||||
Execute (Load plugin from PlugStatus screen with L key in visual mode):
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/z1', { 'on': [] }
|
||||
Plug '$PWD/temp/z2', { 'for': [] }
|
||||
Plug '$PLUG_FIXTURES/z1', { 'on': [] }
|
||||
Plug '$PLUG_FIXTURES/z2', { 'for': [] }
|
||||
call plug#end()
|
||||
|
||||
PlugStatus
|
||||
@@ -964,8 +989,8 @@ Execute (Plug directory with comma):
|
||||
Execute (Strict load order):
|
||||
let g:total_order = []
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/xxx'
|
||||
Plug '$PWD/temp/yyy', { 'for': ['xxx'] }
|
||||
Plug '$PLUG_FIXTURES/xxx'
|
||||
Plug '$PLUG_FIXTURES/yyy', { 'for': ['xxx'] }
|
||||
call plug#end()
|
||||
call EnsureLoaded()
|
||||
setf xxx
|
||||
@@ -977,8 +1002,8 @@ Execute (Strict load order):
|
||||
|
||||
let g:total_order = []
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/xxx', { 'for': ['xxx'] }
|
||||
Plug '$PWD/temp/yyy'
|
||||
Plug '$PLUG_FIXTURES/xxx', { 'for': ['xxx'] }
|
||||
Plug '$PLUG_FIXTURES/yyy'
|
||||
call plug#end()
|
||||
call EnsureLoaded()
|
||||
set rtp^=manually-prepended
|
||||
@@ -994,8 +1019,8 @@ Execute (Strict load order):
|
||||
|
||||
let g:total_order = []
|
||||
call plug#begin()
|
||||
Plug '$PWD/temp/xxx', { 'for': ['xxx'] }
|
||||
Plug '$PWD/temp/yyy', { 'for': ['xxx'] }
|
||||
Plug '$PLUG_FIXTURES/xxx', { 'for': ['xxx'] }
|
||||
Plug '$PLUG_FIXTURES/yyy', { 'for': ['xxx'] }
|
||||
call plug#end()
|
||||
call EnsureLoaded()
|
||||
setf xxx
|
||||
@@ -1007,9 +1032,11 @@ Execute (Strict load order):
|
||||
|
||||
**********************************************************************
|
||||
Execute (PlugClean should not try to remove unmanaged plugins inside g:plug_home):
|
||||
call plug#begin('$PWD/temp')
|
||||
Plug '$PWD/temp/xxx'
|
||||
Plug '$PWD/temp/yyy'
|
||||
call plug#begin('$PLUG_FIXTURES')
|
||||
Plug '$PLUG_FIXTURES/ftplugin-msg', { 'for': [] }
|
||||
Plug '$PLUG_FIXTURES/fzf'
|
||||
Plug '$PLUG_FIXTURES/xxx'
|
||||
Plug '$PLUG_FIXTURES/yyy'
|
||||
call plug#end()
|
||||
|
||||
" Remove z1, z2
|
||||
@@ -1022,6 +1049,24 @@ Execute (PlugClean should not try to remove unmanaged plugins inside g:plug_home
|
||||
AssertExpect 'Already clean', 1
|
||||
q
|
||||
|
||||
**********************************************************************
|
||||
Execute (#112 On-demand loading should not suppress messages from ftplugin):
|
||||
call plug#begin('$PLUG_FIXTURES')
|
||||
Plug '$PLUG_FIXTURES/ftplugin-msg', { 'for': 'c' }
|
||||
call plug#end()
|
||||
|
||||
redir => out
|
||||
tabnew a.c
|
||||
redir END
|
||||
Assert stridx(out, 'ftplugin') >= 0
|
||||
|
||||
* The same applies to plug#load())
|
||||
redir => out
|
||||
call plug#load('ftplugin-msg')
|
||||
redir END
|
||||
Assert stridx(out, 'ftplugin') >= 0
|
||||
q
|
||||
|
||||
**********************************************************************
|
||||
Execute (PlugSnapshot):
|
||||
call plug#begin('$TMPDIR/plugged')
|
||||
@@ -1044,10 +1089,20 @@ Execute (PlugSnapshot):
|
||||
AssertEqual 'snapshot.sh', fnamemodify(expand('%'), ':t')
|
||||
q
|
||||
|
||||
**********************************************************************
|
||||
Execute (#114 Should not contain empty path in &rtp):
|
||||
call plug#begin('$TMPDIR/plugged')
|
||||
call plug#end()
|
||||
|
||||
Log &rtp
|
||||
Assert &rtp !~ ',,', 'Commas'
|
||||
Assert &rtp !~ '^,', 'Comma prefix'
|
||||
Assert &rtp !~ ',$', 'Comma suffix'
|
||||
|
||||
Execute (Cleanup):
|
||||
silent! call system('rm -rf '.temp_plugged)
|
||||
silent! call system('rm -rf '.temp_plugged)
|
||||
silent! call rename('fzf', 'fzf-staged')
|
||||
silent! call rename(fzf, expand('$PLUG_FIXTURES/fzf-staged'))
|
||||
silent! unlet g:plugs
|
||||
silent! unlet g:plug_home
|
||||
silent! unlet g:plug_url_format
|
||||
|
||||
Reference in New Issue
Block a user