28 Commits
0.5.1 ... 0.5.4

Author SHA1 Message Date
Junegunn Choi
f7ebba7b9e Improve PlugDiff: 'X' key to revert the update 2014-08-10 16:52:26 +09:00
Junegunn Choi
6272f5e289 Improve PlugStatus
- Display load status
- Load plugin with 'L' key

(This commit also allows not loading a plugin with `'for': []`. It used
to load ftdetect files.)
2014-08-10 13:46:46 +09:00
Junegunn Choi
f43067c7a5 Merge pull request #51 from junegunn/public-api
Add plug#helptags and plug#load (#48)
2014-08-09 23:44:59 +09:00
Junegunn Choi
e6cba28997 Fix error messages 2014-08-09 13:11:41 +09:00
Junegunn Choi
f1b8832a13 Add plug#load() (#48) 2014-08-09 12:59:20 +09:00
Junegunn Choi
d0c94a9b08 Add plug#helptags() 2014-08-09 12:58:16 +09:00
Junegunn Choi
3a2e406cd0 Merge pull request #47 from junegunn/fix-upgrade
Do not require reloading of .vimrc after PlugUpgrade
2014-08-05 19:09:17 +09:00
Junegunn Choi
84cdf61730 Do not require reloading of .vimrc after PlugUpgrade 2014-08-05 18:52:19 +09:00
Junegunn Choi
0aeea1db08 Update README.md 2014-08-05 15:32:28 +09:00
Junegunn Choi
8289477d18 Revert "Make sure update/install after PlugUpgrade work"
This reverts commit 19b12e2216.

No luck. The user still have to reload .vimrc anyway. Let's just make it
clear that a restart can be required after PlugUpgrade.
2014-08-05 01:50:03 +09:00
Junegunn Choi
19b12e2216 Make sure update/install after PlugUpgrade work
By not assuming `frozen` property exists. I tried to fix it with
s:upgrade_specs, but it has no effect if the old version of vim-plug
doesn't know about it.
2014-08-05 01:43:42 +09:00
Junegunn Choi
4c9ebe9c31 Add -bar option to commands 2014-08-05 01:31:19 +09:00
Junegunn Choi
74dcd13575 s:upgrade_specs should be called after reloading the source 2014-08-05 01:25:34 +09:00
Junegunn Choi
518f20652f Merge pull request #46 from vheon/fix-multiple-create-directory
Do not try to create g:plug_home more than once
2014-08-05 00:56:26 +09:00
Andrea Cedraro
665ec057d7 Do not try to create g:plug_home more than once 2014-08-04 17:43:34 +02:00
Junegunn Choi
bc212dca77 Merge pull request #45 from junegunn/travis-ci-rubies
Test against multiple versions of Ruby
2014-08-04 16:40:11 +09:00
Junegunn Choi
8da7b50fb2 Test against multiple versions of Ruby
As discussed in junegunn/vim-plug#31
2014-08-04 16:31:05 +09:00
Junegunn Choi
4ae2e879e1 Note on escaping double quotes in inline expression 2014-08-02 14:04:03 +09:00
Junegunn Choi
93628b1c3d Forced run of post-update hooks using bang commands
PlugInstall! / PlugUpdate!
2014-08-02 12:13:52 +09:00
Junegunn Choi
01e126469b Remove duplicate expression and escape helptags directory 2014-08-02 02:52:56 +09:00
Junegunn Choi
a7477f04b7 Update README 2014-08-02 01:12:01 +09:00
Junegunn Choi
0fdb56ba72 Update README 2014-08-02 01:00:59 +09:00
Junegunn Choi
d89949f16c Update README.md 2014-08-01 23:46:50 +09:00
Junegunn Choi
19b8221c14 Update README 2014-08-01 23:37:19 +09:00
Junegunn Choi
336fadd236 Remove FAQ/Troubleshooting section and add link to wiki page 2014-08-01 23:33:26 +09:00
Junegunn Choi
a216e38a59 Merge pull request #44 from FriedSock/test_refactoring
Force use of bash for Vader tests.
2014-08-01 23:26:26 +09:00
Jack Bracewell
d930594686 Force use of bash for Vader tests.
If not using a bash compatible shell (like fish), then this will be
set as the default Vim shell. Leading to half the tests failing with
E484: CAN’T OPEN FILE
2014-08-01 15:16:21 +01:00
Junegunn Choi
f4261711ae Update README 2014-08-01 02:01:31 +09:00
5 changed files with 371 additions and 187 deletions

View File

@@ -1,4 +1,7 @@
language: vim language: ruby
rvm:
- 1.8.7
- 2.0.0
before_script: | before_script: |
hg clone https://code.google.com/p/vim/ hg clone https://code.google.com/p/vim/

140
README.md
View File

@@ -1,25 +1,22 @@
![vim-plug](https://raw.github.com/junegunn/vim-plug/master/plug.png) ![vim-plug](https://raw.github.com/junegunn/vim-plug/master/plug.png)
![travis-ci](https://travis-ci.org/junegunn/vim-plug.svg?branch=master) ![travis-ci](https://travis-ci.org/junegunn/vim-plug.svg?branch=master)
A single-file Vim plugin manager. A minimalist Vim plugin manager.
Somewhere between [Pathogen](https://github.com/tpope/vim-pathogen) and
[Vundle](https://github.com/gmarik/vundle), but with faster parallel installer.
![](https://raw.github.com/junegunn/i/master/vim-plug/installer.gif) ![](https://raw.github.com/junegunn/i/master/vim-plug/installer.gif)
### Pros. ### Pros.
- Easier to setup - Easier to setup: Single file. No boilerplate code required.
- Parallel installation/update (requires - Easier to use: Concise, intuitive syntax
[+ruby](http://junegunn.kr/2013/09/installing-vim-with-ruby-support/)) - [Super-fast](https://raw.github.com/junegunn/i/master/vim-plug/40-in-4.gif)
- Smallest possible feature set parallel installation/update (requires
- Branch/tag support [+ruby](https://github.com/junegunn/vim-plug/wiki/ruby))
- On-demand loading - On-demand loading to achieve
[fast startup time](http://junegunn.kr/images/vim-startup-time.png)
### Cons. - Post-update hooks
- Can choose a specific branch or tag for each plugin
- Everything else - Support for externally managed plugins
### Usage ### Usage
@@ -28,7 +25,8 @@ and put it in ~/.vim/autoload
```sh ```sh
mkdir -p ~/.vim/autoload mkdir -p ~/.vim/autoload
curl -fLo ~/.vim/autoload/plug.vim https://raw.github.com/junegunn/vim-plug/master/plug.vim curl -fLo ~/.vim/autoload/plug.vim \
https://raw.github.com/junegunn/vim-plug/master/plug.vim
``` ```
Edit your .vimrc Edit your .vimrc
@@ -63,14 +61,14 @@ Reload .vimrc and `:PlugInstall` to install plugins.
### Commands ### Commands
| Command | Description | | Command | Description |
| --------------------------------- | ------------------------------------------------------------------ | | ----------------------------------- | ------------------------------------------------------------------ |
| PlugInstall [name ...] [#threads] | Install plugins | | `PlugInstall [name ...] [#threads]` | Install plugins |
| PlugUpdate [name ...] [#threads] | Install or update plugins | | `PlugUpdate [name ...] [#threads]` | Install or update plugins |
| PlugClean[!] | Remove unused directories (bang version will clean without prompt) | | `PlugClean[!]` | Remove unused directories (bang version will clean without prompt) |
| PlugUpgrade | Upgrade vim-plug itself | | `PlugUpgrade` | Upgrade vim-plug itself |
| PlugStatus | Check the status of plugins | | `PlugStatus` | Check the status of plugins |
| PlugDiff | See the updated changes from the previous PlugUpdate | | `PlugDiff` | See the updated changes from the previous PlugUpdate |
### `Plug` options ### `Plug` options
@@ -98,6 +96,10 @@ Reload .vimrc and `:PlugInstall` to install plugins.
- `S` - `PlugStatus` - `S` - `PlugStatus`
- `R` - Retry failed update or installation tasks - `R` - Retry failed update or installation tasks
- `q` - Close the window - `q` - Close the window
- `:PlugStatus`
- `L` - Load plugin
- `:PlugDiff`
- `X` - Revert the update
### Example: A small [sensible](https://github.com/tpope/vim-sensible) Vim configuration ### Example: A small [sensible](https://github.com/tpope/vim-sensible) Vim configuration
@@ -123,7 +125,7 @@ Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' } Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' }
``` ```
### Post-installation/update hooks ### Post-update hooks
There are some plugins that require extra steps after installation or update. There are some plugins that require extra steps after installation or update.
In that case, use `do` option to describe the task to be performed. In that case, use `do` option to describe the task to be performed.
@@ -137,10 +139,11 @@ takes a single argument.
```vim ```vim
function! BuildYCM(info) function! BuildYCM(info)
" info is a dictionary with two fields " info is a dictionary with 3 fields
" - name: name of the plugin " - name: name of the plugin
" - status: 'installed' or 'updated' " - status: 'installed', 'updated', or 'unchanged'
if a:info.status == 'installed' " - force: set on PlugInstall! or PlugUpdate!
if a:info.status == 'installed' || a:info.force
!./install.sh !./install.sh
endif endif
endfunction endfunction
@@ -148,10 +151,14 @@ endfunction
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') } Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') }
``` ```
Both forms of post-update hook are executed inside the directory of the plugin. Both forms of post-update hook are executed inside the directory of the plugin
and only run when the repository has changed, but you can force it to run
unconditionally with the bang-versions of the commands: `PlugInstall!` and
`PlugUpdate!`.
Make sure to escape BARs when you write `do` option inline as they are Make sure to escape BARs and double-quotes when you write `do` option inline
mistakenly recognized as command separator for Plug command. as they are mistakenly recognized as command separator or the start of the
trailing comment.
```vim ```vim
Plug 'junegunn/fzf', { 'do': 'yes \| ./install' } Plug 'junegunn/fzf', { 'do': 'yes \| ./install' }
@@ -165,75 +172,16 @@ let g:fzf_install = 'yes | ./install'
Plug 'junegunn/fzf', { 'do': g:fzf_install } Plug 'junegunn/fzf', { 'do': g:fzf_install }
``` ```
### FAQ/Troubleshooting
See [FAQ/Troubleshooting](https://github.com/junegunn/vim-plug/wiki/faq).
### Articles ### Articles
- [Writing my own Vim plugin manager](http://junegunn.kr/2013/09/writing-my-own-vim-plugin-manager) - [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) - [Vim plugins and startup time](http://junegunn.kr/2014/07/vim-plugins-and-startup-time)
- ~~[Thoughts on Vim plugin dependency](http://junegunn.kr/2013/09/thoughts-on-vim-plugin-dependency)~~
### FAQ/Troubleshooting - *Support for Plugfile has been removed since 0.5.0*
#### Plugins are not installed/updated in parallel
Your Vim does not support Ruby interface. `:echo has('ruby')` should print 1.
In order to setup Vim with Ruby support, you may refer to [this
article](http://junegunn.kr/2013/09/installing-vim-with-ruby-support).
#### *Vim: Caught deadly signal SEGV*
If your Vim crashes with the above message, first check if its Ruby interface is
working correctly with the following command:
```vim
:ruby puts RUBY_VERSION
```
If Vim crashes even with this command, it is likely that Ruby interface is
broken, and you have to rebuild Vim with a working version of Ruby.
(`brew remove vim && brew install vim` or `./configure && make ...`)
If you're on OS X, one possibility is that you had installed Vim with
[Homebrew](http://brew.sh/) while using a Ruby installed with
[RVM](http://rvm.io/) or [rbenv](https://github.com/sstephenson/rbenv) and later
removed that version of Ruby.
[Please let me know](https://github.com/junegunn/vim-plug/issues) if you can't
resolve the problem. In the meantime, you can set `g:plug_threads` to 1, so that
Ruby installer is not used at all.
#### Errors on fish shell
If vim-plug doesn't work correctly on fish shell, you might need to add `set
shell=/bin/sh` to your .vimrc.
Refer to the following links for the details:
- http://badsimplicity.com/vim-fish-e484-cant-open-file-tmpvrdnvqe0-error/
- https://github.com/junegunn/vim-plug/issues/12
#### Freezing plugin version with commit hash
vim-plug does not allow you to freeze the version of a plugin with its commit
hash. This is by design. I don't believe a user of a plugin should be looking
at its individual commits. Instead, one should be choosing the right version
using release tags or versioned branches (e.g. 1.2.3, stable, devel, etc.)
```vim
Plug 'junegunn/vim-easy-align', '2.9.2'
```
If the repository doesn't come with such tags or branches, you should think of
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.
#### Migrating from other plugin managers
vim-plug does not require any extra statement other than `plug#begin()` and
`plug#end()`. You can remove `filetype off`, `filetype plugin indent on` and
`syntax on` from your .vimrc as they are automatically handled by
`plug#end()`.
### License ### License

251
plug.vim
View File

@@ -69,7 +69,7 @@ let s:cpo_save = &cpo
set cpo&vim set cpo&vim
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim' let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
let s:plug_buf = -1 let s:plug_buf = get(s:, 'plug_buf', -1)
let s:mac_gui = has('gui_macvim') && has('gui_running') let s:mac_gui = has('gui_macvim') && has('gui_running')
let s:is_win = has('win32') || has('win64') let s:is_win = has('win32') || has('win64')
let s:me = expand('<sfile>:p') let s:me = expand('<sfile>:p')
@@ -80,6 +80,7 @@ let s:TYPE = {
\ 'dict': type({}), \ 'dict': type({}),
\ 'funcref': type(function('call')) \ 'funcref': type(function('call'))
\ } \ }
let s:loaded = get(s:, 'loaded', {})
function! plug#begin(...) function! plug#begin(...)
if a:0 > 0 if a:0 > 0
@@ -92,13 +93,6 @@ function! plug#begin(...)
return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.') return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.')
endif endif
if !isdirectory(home)
try
call mkdir(home, 'p')
catch
return s:err('Invalid plug directory: '. home)
endtry
endif
if !executable('git') if !executable('git')
return s:err('`git` executable not found. vim-plug requires git.') return s:err('`git` executable not found. vim-plug requires git.')
endif endif
@@ -108,17 +102,20 @@ function! plug#begin(...)
" we want to keep track of the order plugins where registered. " we want to keep track of the order plugins where registered.
let g:plugs_order = [] let g:plugs_order = []
command! -nargs=+ -bar Plug call s:add(<args>) call s:define_commands()
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>' == '!')
command! -nargs=0 PlugUpgrade if s:upgrade() | call s:upgrade_specs() | execute 'source '. s:me | endif
command! -nargs=0 PlugStatus call s:status()
command! -nargs=0 PlugDiff call s:diff()
return 1 return 1
endfunction endfunction
function! s:define_commands()
command! -nargs=+ -bar Plug call s:add(<args>)
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('<bang>' == '!', <f-args>)
command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('<bang>' == '!', <f-args>)
command! -nargs=0 -bar -bang PlugClean call s:clean('<bang>' == '!')
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source '. s:me | endif
command! -nargs=0 -bar PlugStatus call s:status()
command! -nargs=0 -bar PlugDiff call s:diff()
endfunction
function! s:to_a(v) function! s:to_a(v)
return type(a:v) == s:TYPE.list ? a:v : [a:v] return type(a:v) == s:TYPE.list ? a:v : [a:v]
endfunction endfunction
@@ -152,9 +149,8 @@ function! plug#end()
" need to loop through the plugins in reverse " need to loop through the plugins in reverse
for name in reverse(copy(g:plugs_order)) for name in reverse(copy(g:plugs_order))
let plug = g:plugs[name] let plug = g:plugs[name]
if !has_key(plug, 'on') && !has_key(plug, 'for') if get(s:loaded, plug.dir, 0) || !has_key(plug, 'on') && !has_key(plug, 'for')
let rtp = s:rtp(plug) let rtp = s:add_rtp(plug)
call s:add_rtp(rtp)
if reload if reload
call s:source(rtp, 'plugin/**/*.vim', 'after/plugin/**/*.vim') call s:source(rtp, 'plugin/**/*.vim', 'after/plugin/**/*.vim')
endif endif
@@ -181,8 +177,11 @@ function! plug#end()
endif endif
if has_key(plug, 'for') if has_key(plug, 'for')
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim') let types = s:to_a(plug.for)
for key in s:to_a(plug.for) if !empty(types)
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
endif
for key in types
if !has_key(lod, key) if !has_key(lod, key)
let lod[key] = [] let lod[key] = []
endif endif
@@ -251,12 +250,15 @@ function! s:esc(path)
return substitute(a:path, ' ', '\\ ', 'g') return substitute(a:path, ' ', '\\ ', 'g')
endfunction endfunction
function! s:add_rtp(rtp) function! s:add_rtp(plug)
execute 'set rtp^='.s:esc(a:rtp) let rtp = s:rtp(a:plug)
let after = globpath(a:rtp, 'after') execute 'set rtp^='.s:esc(rtp)
let after = globpath(rtp, 'after')
if isdirectory(after) if isdirectory(after)
execute 'set rtp+='.s:esc(after) execute 'set rtp+='.s:esc(after)
endif endif
let s:loaded[a:plug.dir] = 1
return rtp
endfunction endfunction
function! s:reorg_rtp() function! s:reorg_rtp()
@@ -270,9 +272,28 @@ function! s:reorg_rtp()
endif endif
endfunction 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) function! s:lod(plug, types)
let rtp = s:rtp(a:plug) let rtp = s:add_rtp(a:plug)
call s:add_rtp(rtp)
for dir in a:types for dir in a:types
call s:source(rtp, dir.'/**/*.vim') call s:source(rtp, dir.'/**/*.vim')
endfor endfor
@@ -323,6 +344,7 @@ function! s:add(repo, ...)
\ a:0 == 1 ? s:parse_options(a:1) : s:base_spec) \ a:0 == 1 ? s:parse_options(a:1) : s:base_spec)
let g:plugs[name] = spec let g:plugs[name] = spec
let g:plugs_order += [name] let g:plugs_order += [name]
let s:loaded[spec.dir] = 0
catch catch
return s:err(v:exception) return s:err(v:exception)
endtry endtry
@@ -365,21 +387,25 @@ function! s:infer_properties(name, repo)
endif endif
endfunction endfunction
function! s:install(...) function! s:install(force, ...)
call s:update_impl(0, a:000) call s:update_impl(0, a:force, a:000)
endfunction endfunction
function! s:update(...) function! s:update(force, ...)
call s:update_impl(1, a:000) call s:update_impl(1, a:force, a:000)
endfunction 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) for spec in values(g:plugs)
let docd = join([spec.dir, 'doc'], '/') let docd = join([spec.dir, 'doc'], '/')
if isdirectory(docd) if isdirectory(docd)
silent! execute 'helptags '. join([spec.dir, 'doc'], '/') silent! execute 'helptags '. s:esc(docd)
endif endif
endfor endfor
return 1
endfunction endfunction
function! s:syntax() function! s:syntax()
@@ -399,6 +425,7 @@ function! s:syntax()
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha
syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained
syn match plugRelDate /([^)]*)$/ contained syn match plugRelDate /([^)]*)$/ contained
syn match plugNotLoaded /(not loaded)$/
syn match plugError /^x.*/ syn match plugError /^x.*/
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
hi def link plug1 Title hi def link plug1 Title
@@ -419,6 +446,8 @@ function! s:syntax()
hi def link plugError Error hi def link plugError Error
hi def link plugRelDate Comment hi def link plugRelDate Comment
hi def link plugSha Identifier hi def link plugSha Identifier
hi def link plugNotLoaded Comment
endfunction endfunction
function! s:lpad(str, len) function! s:lpad(str, len)
@@ -439,6 +468,7 @@ function! s:prepare()
else else
execute winnr . 'wincmd w' execute winnr . 'wincmd w'
endif endif
setlocal modifiable
silent %d _ silent %d _
else else
vertical topleft new vertical topleft new
@@ -453,7 +483,9 @@ function! s:prepare()
call s:assign_name() call s:assign_name()
endif endif
silent! unmap <buffer> <cr> silent! unmap <buffer> <cr>
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline silent! unmap <buffer> L
silent! unmap <buffer> X
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline modifiable
setf vim-plug setf vim-plug
call s:syntax() call s:syntax()
endfunction endfunction
@@ -470,15 +502,16 @@ function! s:assign_name()
silent! execute 'f '.fnameescape(name) silent! execute 'f '.fnameescape(name)
endfunction endfunction
function! s:do(pull, todo) function! s:do(pull, force, todo)
for [name, spec] in items(a:todo) for [name, spec] in items(a:todo)
if !isdirectory(spec.dir) if !isdirectory(spec.dir)
continue continue
endif endif
execute 'cd '.s:esc(spec.dir) execute 'cd '.s:esc(spec.dir)
let installed = has_key(s:prev_update.new, name) let installed = has_key(s:prev_update.new, name)
if installed || (a:pull && let updated = installed ? 0 :
\ !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"'))) \ (a:pull && !empty(s:system_chomp('git log --pretty=format:"%h" "HEAD...HEAD@{1}"')))
if a:force || installed || updated
call append(3, '- Post-update hook for '. name .' ... ') call append(3, '- Post-update hook for '. name .' ... ')
let type = type(spec.do) let type = type(spec.do)
if type == s:TYPE.string if type == s:TYPE.string
@@ -493,7 +526,8 @@ function! s:do(pull, todo)
endtry endtry
elseif type == s:TYPE.funcref elseif type == s:TYPE.funcref
try try
call spec.do({ 'name': name, 'status': (installed ? 'installed' : 'updated') }) let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged')
call spec.do({ 'name': name, 'status': status, 'force': a:force })
let result = 'Done!' let result = 'Done!'
catch catch
let result = 'Error: ' . v:exception let result = 'Error: ' . v:exception
@@ -510,7 +544,7 @@ endfunction
function! s:finish(pull) function! s:finish(pull)
call append(3, '- Finishing ... ') call append(3, '- Finishing ... ')
redraw redraw
call s:helptags() call plug#helptags()
call plug#end() call plug#end()
call setline(4, getline(4) . 'Done!') call setline(4, getline(4) . 'Done!')
normal! gg normal! gg
@@ -530,7 +564,7 @@ function! s:retry()
if empty(s:prev_update.errors) if empty(s:prev_update.errors)
return return
endif endif
call s:update_impl(s:prev_update.pull, call s:update_impl(s:prev_update.pull, s:prev_update.force,
\ extend(copy(s:prev_update.errors), [s:prev_update.threads])) \ extend(copy(s:prev_update.errors), [s:prev_update.threads]))
endfunction endfunction
@@ -542,7 +576,7 @@ function! s:names(...)
return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)') return filter(keys(g:plugs), 'stridx(v:val, a:1) == 0 && s:is_managed(v:val)')
endfunction endfunction
function! s:update_impl(pull, args) abort function! s:update_impl(pull, force, args) abort
let st = reltime() let st = reltime()
let args = copy(a:args) let args = copy(a:args)
let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ? let threads = (len(args) > 0 && args[-1] =~ '^[1-9][0-9]*$') ?
@@ -559,16 +593,22 @@ function! s:update_impl(pull, args) abort
return return
endif endif
if !isdirectory(g:plug_home)
try
call mkdir(g:plug_home, 'p')
catch
return s:err(printf('Invalid plug directory: %s.'
\ 'Try to call plug#begin with a valid directory', g:plug_home))
endtry
endif
call s:prepare() call s:prepare()
call append(0, a:pull ? 'Updating plugins' : 'Installing plugins') call append(0, a:pull ? 'Updating plugins' : 'Installing plugins')
call append(1, '['. s:lpad('', len(todo)) .']') call append(1, '['. s:lpad('', len(todo)) .']')
normal! 2G normal! 2G
redraw redraw
if !isdirectory(g:plug_home) let s:prev_update = { 'errors': [], 'pull': a:pull, 'force': a:force, 'new': {}, 'threads': threads }
call mkdir(g:plug_home, 'p')
endif
let s:prev_update = { 'errors': [], 'pull': a:pull, 'new': {}, 'threads': threads }
if has('ruby') && threads > 1 if has('ruby') && threads > 1
try try
let imd = &imd let imd = &imd
@@ -598,7 +638,7 @@ function! s:update_impl(pull, args) abort
else else
call s:update_serial(a:pull, todo) call s:update_serial(a:pull, todo)
endif endif
call s:do(a:pull, filter(copy(todo), 'has_key(v:val, "do")')) call s:do(a:pull, a:force, filter(copy(todo), 'has_key(v:val, "do")'))
call s:finish(a:pull) call s:finish(a:pull)
call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(st)))[0] . ' sec.') call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(st)))[0] . ' sec.')
endfunction endfunction
@@ -1002,16 +1042,13 @@ function! s:upgrade()
call system(printf( call system(printf(
\ 'curl -fLo %s %s && '.cp.' %s %s.old && '.mv.' %s %s', \ 'curl -fLo %s %s && '.cp.' %s %s.old && '.mv.' %s %s',
\ new, s:plug_source, mee, mee, new, mee)) \ new, s:plug_source, mee, mee, new, mee))
if v:shell_error == 0 if v:shell_error
unlet g:loaded_plug
echo 'Downloaded '. s:plug_source
return 1
else
return s:err('Error upgrading vim-plug') return s:err('Error upgrading vim-plug')
endif endif
elseif has('ruby') elseif has('ruby')
echo 'Downloading '. s:plug_source echo 'Downloading '. s:plug_source
ruby << EOF try
ruby << EOF
require 'open-uri' require 'open-uri'
require 'fileutils' require 'fileutils'
me = VIM::evaluate('s:me') me = VIM::evaluate('s:me')
@@ -1023,12 +1060,16 @@ function! s:upgrade()
FileUtils.cp me, old FileUtils.cp me, old
File.rename new, me File.rename new, me
EOF EOF
unlet g:loaded_plug catch
echo 'Downloaded '. s:plug_source return s:err('Error upgrading vim-plug')
return 1 endtry
else else
return s:err('curl executable or ruby support not found') return s:err('curl executable or ruby support not found')
endif endif
unlet g:loaded_plug
echo 'Downloaded '. s:plug_source
return 1
endfunction endfunction
function! s:upgrade_specs() function! s:upgrade_specs()
@@ -1043,6 +1084,7 @@ function! s:status()
call append(1, '') call append(1, '')
let ecnt = 0 let ecnt = 0
let unloaded = 0
let [cnt, total] = [0, len(g:plugs)] let [cnt, total] = [0, len(g:plugs)]
for [name, spec] in items(g:plugs) for [name, spec] in items(g:plugs)
if has_key(spec, 'uri') if has_key(spec, 'uri')
@@ -1060,6 +1102,11 @@ function! s:status()
endif endif
let cnt += 1 let cnt += 1
let ecnt += !valid let ecnt += !valid
" `s:loaded` entry can be missing if PlugUpgraded
if valid && get(s:loaded, spec.dir, -1) == 0
let unloaded = 1
let msg .= ' (not loaded)'
endif
call s:progress_bar(2, repeat('=', cnt), total) call s:progress_bar(2, repeat('=', cnt), total)
call append(3, s:format_message(valid, name, msg)) call append(3, s:format_message(valid, name, msg))
normal! 2G normal! 2G
@@ -1067,6 +1114,24 @@ function! s:status()
endfor endfor
call setline(1, 'Finished. '.ecnt.' error(s).') call setline(1, 'Finished. '.ecnt.' error(s).')
normal! gg normal! gg
setlocal nomodifiable
if unloaded
echo "Press 'L' on each line to load plugin"
nnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
xnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
end
endfunction
function! s:status_load(lnum)
let line = getline(a:lnum)
let matches = matchlist(line, '^- \([^:]*\):.*(not loaded)$')
if !empty(matches)
let name = matches[1]
call plug#load(name)
setlocal modifiable
call setline(a:lnum, substitute(line, ' (not loaded)$', '', ''))
setlocal nomodifiable
endif
endfunction endfunction
function! s:is_preview_window_open() function! s:is_preview_window_open()
@@ -1078,34 +1143,43 @@ function! s:is_preview_window_open()
return 0 return 0
endfunction endfunction
function! s:find_name(lnum)
for lnum in reverse(range(1, a:lnum))
let line = getline(lnum)
if empty(line)
return ''
endif
let name = matchstr(line, '\(^- \)\@<=[^:]\+')
if !empty(name)
return name
endif
endfor
return ''
endfunction
function! s:preview_commit() function! s:preview_commit()
if b:plug_preview < 0 if b:plug_preview < 0
let b:plug_preview = !s:is_preview_window_open() let b:plug_preview = !s:is_preview_window_open()
endif endif
let sha = matchstr(getline('.'), '\(^ \)\@<=[0-9a-z]\{7}') let sha = matchstr(getline('.'), '\(^ \)\@<=[0-9a-z]\{7}')
if !empty(sha) if empty(sha)
let lnum = line('.') return
while lnum > 1
let lnum -= 1
let line = getline(lnum)
let name = matchstr(line, '\(^- \)\@<=[^:]\+')
if !empty(name)
let dir = g:plugs[name].dir
if isdirectory(dir)
execute 'cd '.s:esc(dir)
execute 'pedit '.sha
wincmd P
setlocal filetype=git buftype=nofile nobuflisted
execute 'silent read !git show '.sha
normal! ggdd
wincmd p
cd -
endif
break
endif
endwhile
endif endif
let name = s:find_name(line('.'))
if empty(name) || !has_key(g:plugs, name) || !isdirectory(g:plugs[name].dir)
return
endif
execute 'cd '.s:esc(g:plugs[name].dir)
execute 'pedit '.sha
wincmd P
setlocal filetype=git buftype=nofile nobuflisted
execute 'silent read !git show '.sha
normal! ggdd
wincmd p
cd -
endfunction endfunction
function! s:section(flags) function! s:section(flags)
@@ -1139,12 +1213,39 @@ function! s:diff()
call setline(1, cnt == 0 ? 'No updates.' : 'Last update:') call setline(1, cnt == 0 ? 'No updates.' : 'Last update:')
nnoremap <silent> <buffer> <cr> :silent! call <SID>preview_commit()<cr> nnoremap <silent> <buffer> <cr> :silent! call <SID>preview_commit()<cr>
nnoremap <silent> <buffer> X :call <SID>revert()<cr>
normal! gg normal! gg
setlocal nomodifiable
if cnt > 0
echo "Press 'X' on each block to revert the update"
endif
endfunction
function! s:revert()
let name = s:find_name(line('.'))
if empty(name) || !has_key(g:plugs, name) ||
\ input(printf('Revert the update of %s? (Y/N) ', name)) !~? '^y'
return
endif
execute 'cd '.s:esc(g:plugs[name].dir)
call system('git reset --hard HEAD@{1} && git checkout '.s:esc(g:plugs[name].branch))
cd -
setlocal modifiable
normal! dap
setlocal nomodifiable
echo 'Reverted.'
endfunction endfunction
let s:first_rtp = s:esc(get(split(&rtp, ','), 0, '')) let s:first_rtp = s:esc(get(split(&rtp, ','), 0, ''))
let s:last_rtp = s:esc(get(split(&rtp, ','), -1, '')) let s:last_rtp = s:esc(get(split(&rtp, ','), -1, ''))
if exists('g:plugs')
let g:plugs_order = get(g:, 'plugs_order', keys(g:plugs))
call s:upgrade_specs()
call s:define_commands()
endif
let &cpo = s:cpo_save let &cpo = s:cpo_save
unlet s:cpo_save unlet s:cpo_save

View File

@@ -21,18 +21,27 @@ make_dirs() {
for d in *; do for d in *; do
cat > $d/xxx.vim << EOF cat > $d/xxx.vim << EOF
" echom expand('<sfile>') " echom expand('<sfile>')
let g:xxx = get(g:, 'xxx', []) let g:$2 = get(g:, '$2', [])
call add(g:xxx, '${1:4}/$d') call add(g:$2, '${1:4}/$d')
EOF EOF
done done
cd - > /dev/null cd - > /dev/null
} }
make_dirs xxx/ make_dirs xxx/ xxx
make_dirs xxx/after make_dirs xxx/after xxx
mkdir xxx/doc
cat > xxx/doc/xxx.txt << DOC
hello *xxx*
DOC
make_dirs yyy/ yyy
make_dirs z1/ z1
make_dirs z2/ z2
cat > /tmp/mini-vimrc << VIMRC cat > /tmp/mini-vimrc << VIMRC
set rtp+=vader.vim set rtp+=vader.vim
set shell=/bin/bash
source $PLUG_SRC source $PLUG_SRC
VIMRC VIMRC

View File

@@ -33,6 +33,12 @@ Execute (Initialize test environment):
endfunction endfunction
command! -nargs=+ -bang AssertExpect call AssertExpect('<bang>' == '!', <args>) command! -nargs=+ -bang AssertExpect call AssertExpect('<bang>' == '!', <args>)
Execute (Print Ruby version):
redir => out
silent ruby puts RUBY_VERSION
redir END
Log substitute(out, '\n', '', 'g')
Execute (plug#end() before plug#begin() should fail): Execute (plug#end() before plug#begin() should fail):
redir => out redir => out
AssertEqual 0, plug#end() AssertEqual 0, plug#end()
@@ -301,6 +307,13 @@ Execute (Rollback recent updates, PlugUpdate, then PlugDiff):
AssertEqual lnum, line('.') AssertEqual lnum, line('.')
AssertEqual 3, col('.') AssertEqual 3, col('.')
" X key to revert the update
AssertExpect '^- ', 2
execute "normal Xn\<cr>"
AssertExpect '^- ', 2
execute "normal Xy\<cr>"
AssertExpect '^- ', 1
" q will close preview window as well " q will close preview window as well
normal q normal q
@@ -311,6 +324,7 @@ Execute (Rollback recent updates, PlugUpdate, then PlugDiff):
" q should not close preview window if it's already open " q should not close preview window if it's already open
pedit pedit
PlugDiff PlugDiff
AssertExpect '^- ', 1
execute "normal ]]j\<cr>" execute "normal ]]j\<cr>"
normal q normal q
@@ -324,8 +338,8 @@ Execute (Plug window in a new tab):
set buftype=nofile set buftype=nofile
PlugUpdate PlugUpdate
normal D normal D
AssertEqual 'No updates.', getline(1) AssertExpect '^- ', 1
q normal q
AssertEqual 'new-tab', expand('%') AssertEqual 'new-tab', expand('%')
q q
q q
@@ -506,15 +520,15 @@ Execute (Frozen plugin are not installed nor updated):
Plug 'junegunn/vim-easy-align', { 'frozen': 1 } Plug 'junegunn/vim-easy-align', { 'frozen': 1 }
call plug#end() call plug#end()
redir => output redir => out
silent PlugInstall silent PlugInstall
redir END redir END
Assert output =~ 'No plugin to install' Assert out =~ 'No plugin to install'
redir => output redir => out
silent PlugUpdate silent PlugUpdate
redir END redir END
Assert output =~ 'No plugin to update' Assert out =~ 'No plugin to update'
Execute (But you can still install it if the name is given as the argument): Execute (But you can still install it if the name is given as the argument):
PlugInstall vim-easy-align PlugInstall vim-easy-align
@@ -621,6 +635,14 @@ Execute (When already installed):
Assert !filereadable(g:plugs['vim-easy-align'].dir.'/installed2'), Assert !filereadable(g:plugs['vim-easy-align'].dir.'/installed2'),
\ 'vim-easy-align/installed2 should not exist' \ 'vim-easy-align/installed2 should not exist'
Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'), Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'),
\ 'vim-pseudocl/installed2 should not exist'
Execute (PlugInstall!):
PlugInstall!
q
Assert filereadable(g:plugs['vim-easy-align'].dir.'/installed2'),
\ 'vim-easy-align/installed2 should exist'
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/installed2'),
\ 'vim-pseudocl/installed2 should exist' \ 'vim-pseudocl/installed2 should exist'
Execute (When already updated): Execute (When already updated):
@@ -634,11 +656,19 @@ Execute (When already updated):
Assert !filereadable(g:plugs['vim-easy-align'].dir.'/updated2'), Assert !filereadable(g:plugs['vim-easy-align'].dir.'/updated2'),
\ 'vim-easy-align/updated2 should not exist' \ 'vim-easy-align/updated2 should not exist'
Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'), Assert !filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'),
\ 'vim-pseudocl/updated2 should not exist'
Execute (PlugUpdate!):
PlugUpdate!
q
Assert filereadable(g:plugs['vim-easy-align'].dir.'/updated2'),
\ 'vim-easy-align/updated2 should exist'
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/updated2'),
\ 'vim-pseudocl/updated2 should exist' \ 'vim-pseudocl/updated2 should exist'
Execute (Using Funcref): Execute (Using Funcref):
function! PlugUpdated(info) function! PlugUpdated(info)
call system('touch '. a:info.name . a:info.status . len(a:info)) call system('touch '. a:info.name . a:info.status . a:info.force . len(a:info))
endfunction endfunction
call plug#begin() call plug#begin()
@@ -652,11 +682,26 @@ Execute (Using Funcref):
PlugUpdate PlugUpdate
Log getline(1, '$') Log getline(1, '$')
q q
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated2'), Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated03'),
\ 'vim-easy-align/vim-easy-alignupdated2 should exist' \ 'vim-easy-align/vim-easy-alignupdated03 should exist'
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled2'), Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled03'),
\ 'vim-pseudocl/vim-pseudoclinstalled2 should exist' \ 'vim-pseudocl/vim-pseudoclinstalled03 should exist'
call system('rm -rf '.g:plugs['vim-pseudocl'].dir)
PlugInstall!
q
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignunchanged13'),
\ 'vim-easy-align/vim-easy-alignunchanged13 should exist'
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclinstalled13'),
\ 'vim-pseudocl/vim-pseudoclinstalled13 should exist'
call system('cd '.g:plugs['vim-easy-align'].dir.' && git reset --hard HEAD^')
PlugUpdate!
q
Assert filereadable(g:plugs['vim-easy-align'].dir.'/vim-easy-alignupdated13'),
\ 'vim-easy-align/vim-easy-alignupdated13 should exist'
Assert filereadable(g:plugs['vim-pseudocl'].dir.'/vim-pseudoclunchanged13'),
\ 'vim-pseudocl/vim-pseudoclunchanged13 should exist'
********************************************************************** **********************************************************************
~ Overriding `dir` ~ Overriding `dir`
@@ -725,6 +770,84 @@ Execute (Filetype-based on-demand loading):
AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx AssertEqual ['/ftdetect', 'after/ftdetect', '/plugin', 'after/plugin', '/ftplugin', 'after/ftplugin', '/indent', 'after/indent', '/syntax', 'after/syntax'], g:xxx
Before: Before:
**********************************************************************
~ 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'))
**********************************************************************
~ Manual loading
**********************************************************************
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 (on: []):
call plug#begin()
Plug 'junegunn/rust.vim', { 'on': [] }
call plug#end()
PlugInstall
q
Execute (PlugStatus reports (not loaded)):
PlugStatus
AssertExpect 'not loaded', 1
q
Execute (plug#load to load it):
tabnew test.rs
" Vader will switch tab to [Vader-workbench] after Log
" Log &filetype
AssertEqual 1, plug#load('rust.vim')
AssertEqual 'rust', &filetype
q
Execute (PlugStatus should not contain (not loaded)):
PlugStatus
AssertExpect 'not loaded', 0
q
Execute (Load plugin from PlugStatus screen with L key in normal mode):
call plug#begin()
Plug '$PWD/yyy', { 'on': [] }
call plug#end()
PlugStatus
AssertExpect 'not loaded', 1
Assert !exists('g:yyy'), 'yyy not loaded'
/not loaded
normal L
AssertExpect 'not loaded', 0
Assert exists('g:yyy'), 'yyy loaded'
q
Execute (Load plugin from PlugStatus screen with L key in visual mode):
call plug#begin()
Plug '$PWD/z1', { 'on': [] }
Plug '$PWD/z2', { 'for': [] }
call plug#end()
PlugStatus
AssertExpect 'not loaded', 2
Assert !exists('g:z1'), 'z1 not loaded'
Assert !exists('g:z2'), 'z2 not loaded'
normal ggVGL
AssertExpect 'not loaded', 0
Assert exists('g:z1'), 'z1 loaded'
Assert exists('g:z2'), 'z2 loaded'
q
Execute (Cleanup): 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', 'fzf-staged')