69 Commits
0.5.0 ... 0.5.7

Author SHA1 Message Date
Junegunn Choi
f31477407a Enable syntax only during startup
Related discussion can be found in #83. If the user choose not to use
syntax highlighting, he can disable it by putting `syntax off` after
`plug#end()`. But since `plug#end()` is called by `PlugInstall` or
`PlugUpdate`, it is reenabled on those commands which is not desirable.
This commit fixes the issue by changing `plug#end` to do `syntax enable`
only during Vim startup.
2014-09-23 22:11:31 +09:00
Junegunn Choi
0e907d4f38 Add link to Travis CI page 2014-09-23 15:30:46 +09:00
Junegunn Choi
cb08d6036b Reload plugins after everything's ready 2014-09-23 15:25:05 +09:00
Junegunn Choi
9d63fe6aeb Merge pull request #88 from junegunn/improve-rtp-mgmt
Improve &runtimepath mgmt (fix #85)
2014-09-23 10:14:03 +09:00
Junegunn Choi
0489b5deed Stricter double-comma replacement
To handle paths ending with commas
2014-09-23 10:01:16 +09:00
Junegunn Choi
cac2f9f439 Improve &rtp management (#85)
- Respect the order of `Plug` commands even when some plugins are loaded
  on demand
- Correct the order of `after` directories added to `&rtp`
2014-09-23 00:21:48 +09:00
Junegunn Choi
115a25de79 Suppress error messages from which command 2014-09-19 00:40:27 +09:00
Junegunn Choi
a64b156682 Expand argument to plug#begin (#82) 2014-09-17 19:41:00 +09:00
Junegunn Choi
a9fa8f44e5 Merge pull request #79 from junegunn/U
Add `U` keybinding for updating plugins
2014-09-15 21:12:25 +09:00
Junegunn Choi
d6590fa883 Code cleanup 2014-09-15 21:03:37 +09:00
Junegunn Choi
cabaf7b431 Use blackhole register when deleting lines 2014-09-15 21:02:08 +09:00
Junegunn Choi
6e509db6ff Add U keybinding for updating plugins 2014-09-15 19:12:52 +09:00
Junegunn Choi
7b7778d5ba Remove plugin directory on failure during installation (#75)
If installation process is terminated during `git submodule ...`, the
directory ends up in an inconsistent state. This commit ensures
that the directory is removed on failure.

Fixed Ruby 1.8.7 compatibility.
2014-09-14 13:54:20 +09:00
Junegunn Choi
f3e2d214df Revert "Remove plugin directory on failure during installation (#75)"
This reverts commit 5ec1faefab.
2014-09-14 13:49:00 +09:00
Junegunn Choi
5ec1faefab Remove plugin directory on failure during installation (#75)
If installation process is terminated during `git submodule ...`, the
directory ends up in an inconsistent directory. This commit ensures
that the directory is removed on failure.
2014-09-14 13:41:36 +09:00
Junegunn Choi
6406d73c9a When to use for option 2014-09-10 23:45:22 +09:00
Junegunn Choi
ff4cbe23c0 Throw v:shell_error when system() output is empty 2014-09-10 00:21:39 +09:00
Junegunn Choi
681ca2d43a Refactor PlugUpgrade (#72)
- Remove duplicate code
- Do not create .old file when vim-plug is up-to-date
- Better messages
2014-09-10 00:16:23 +09:00
Junegunn Choi
adb2413f0d syntax enable instead of syntax on 2014-09-05 12:04:28 +09:00
Junegunn Choi
dda21b50bf Merge pull request #67 from stevensons/resolve-symlink
Resolve symlinks in path to plug.vim
2014-09-04 20:12:27 +09:00
Scott Stevenson
537a5321aa Resolve symlinks in path to plug.vim
If `plug.vim` is a symbolic link, `PlugUpgrade` will now download the
latest version to the resolved path rather than overwriting the link.
2014-09-04 10:54:15 +00:00
Junegunn Choi
99f6f36b69 Do not print 'D'-message when there was no update (#66)
This commit assumes that the git pull command prints 'Already
up-to-date' when the repository is up-to-date. Let's just hope that it
doesn't change in the future.
2014-09-04 14:10:33 +09:00
Junegunn Choi
3f82808bea Use blackhole register when deleting commit list 2014-09-04 14:09:06 +09:00
Junegunn Choi
7474edf13f Remove unnecessary dot-concatenations
Thanks to @vheon for the tip.
2014-09-04 01:48:27 +09:00
Junegunn Choi
25b0fb7583 Merge pull request #65 from vheon/fix-preview-commit
[PlugDiff] Change directory after wincmd to avoid side-effects on BufEnter/BufLeave
2014-09-04 01:29:57 +09:00
Andrea Cedraro
a868ee4c11 cd to repo root when in preview window on preview commit 2014-09-03 08:47:01 +02:00
Junegunn Choi
49851436ff Use --no-rebase option on git pull (#64) 2014-09-03 02:14:54 +09:00
Junegunn Choi
2f9a94e8c0 Update README 2014-08-26 01:39:12 +09:00
Junegunn Choi
ab3bd3b17c Implement g:plug_url_format (#62) 2014-08-26 01:36:50 +09:00
Junegunn Choi
3572ffde79 Add g:plug_window to README (#57) 2014-08-20 12:38:22 +09:00
Junegunn Choi
18c8b54793 Add test case for g:plug_window (#57) 2014-08-20 12:33:37 +09:00
Junegunn Choi
1752de5b7c Fix indentation 2014-08-20 12:33:37 +09:00
Miles Whittaker
2f3225fc60 User can now specify how plug window opens
Using 'let g:plug_window = "topleft new"' or something similar, the
user can specify how they would like the plug window to open.
2014-08-20 12:33:37 +09:00
Junegunn Choi
1022acad0b Add example for on-demand loading for multiple file types (#59) 2014-08-20 01:27:55 +09:00
Junegunn Choi
68c7fbbf9d Change raw.github.com url (#58)
https://developer.github.com/changes/2014-04-25-user-content-security/
2014-08-19 20:46:27 +09:00
Junegunn Choi
da24f714e0 Use git:: prefix to avoid password prompt on git 1.7 (#56) 2014-08-14 10:04:44 +09:00
Junegunn Choi
c1bbbaf3ef Allow Plug command even when git executable is not found (#52)
- plug#begin() will return 1 even when git executable is not found
    - Commands that require git will not be available
- If you wish to ignore the error message prepend `silent!` to the call
2014-08-11 01:42:19 +09:00
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
Junegunn Choi
61b77bc8e8 Fix many subtle issues regarding on-demand loading etc.
- On-demand loading
    - Fix loading of unwanted files (e.g. colors/*.vim, syntax/*.vim, etc.)
- Filetyp-based on-demand loading
    - Load `after/ftdetect` as well
    - Make sure indent files are loaded by invoking
      `doautocmd filetypeindent FileType`
- Ensure plugin loaded when it was added after Vim started
- Do not reload $MYVIMRC after installtion/update
    - Instead simply call plug#end()
2014-07-31 16:34:41 +09:00
Junegunn Choi
fe7c7e7b40 Minor tweaks 2014-07-31 03:04:59 +09:00
Junegunn Choi
25afdf138c Refactoring
- Remove dead code
- Extract method
2014-07-31 01:01:59 +09:00
Junegunn Choi
b36fd34da0 Ensure files under after are loaded when first installed 2014-07-31 00:17:21 +09:00
5 changed files with 807 additions and 337 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/

158
README.md
View File

@@ -1,34 +1,32 @@
![vim-plug](https://raw.github.com/junegunn/vim-plug/master/plug.png) ![vim-plug](https://raw.githubusercontent.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)](https://travis-ci.org/junegunn/vim-plug)
A single-file Vim plugin manager. A minimalist Vim plugin manager.
Somewhere between [Pathogen](https://github.com/tpope/vim-pathogen) and ![](https://raw.githubusercontent.com/junegunn/i/master/vim-plug/installer.gif)
[Vundle](https://github.com/gmarik/vundle), but with faster parallel installer.
![](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.githubusercontent.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
[Download plug.vim](https://raw.github.com/junegunn/vim-plug/master/plug.vim) [Download plug.vim](https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim)
and put it in ~/.vim/autoload 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.githubusercontent.com/junegunn/vim-plug/master/plug.vim
``` ```
Edit your .vimrc Edit your .vimrc
@@ -64,13 +62,13 @@ 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
@@ -84,20 +82,27 @@ Reload .vimrc and `:PlugInstall` to install plugins.
| `for` | On-demand loading: File types | | `for` | On-demand loading: File types |
| `frozen` | Do not install/update plugin unless explicitly given as the argument | | `frozen` | Do not install/update plugin unless explicitly given as the argument |
### Options for parallel installer ### Global options
| Flag | Default | Description | | Flag | Default | Description |
| ---------------- | ------- | ------------------------------------ | | ------------------- | --------------------------------- | ------------------------------------ |
| `g:plug_threads` | 16 | Default number of threads to use | | `g:plug_threads` | 16 | Default number of threads to use |
| `g:plug_timeout` | 60 | Time limit of each task in seconds | | `g:plug_timeout` | 60 | Time limit of each task in seconds |
| `g:plug_retries` | 2 | Number of retries in case of timeout | | `g:plug_retries` | 2 | Number of retries in case of timeout |
| `g:plug_window` | `vertical topleft new` | Command to open plug window |
| `g:plug_url_format` | `https://git::@github.com/%s.git` | `printf` format to build repo URL |
### Keybindings ### Keybindings
- `D` - `PlugDiff` - `D` - `PlugDiff`
- `S` - `PlugStatus` - `S` - `PlugStatus`
- `R` - Retry failed update or installation tasks - `R` - Retry failed update or installation tasks
- `U` - Update plugins in the selected range
- `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
@@ -119,11 +124,18 @@ Plug 'junegunn/vim-github-dashboard', { 'on': ['GHDashboard', 'GHActivity'] }
" Loaded when clojure file is opened " Loaded when clojure file is opened
Plug 'tpope/vim-fireplace', { 'for': 'clojure' } Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
" Multiple file types
Plug 'kovisoft/paredit', { 'for': ['clojure', 'scheme'] }
" On-demand loading on both conditions " On-demand loading on both conditions
Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' } Plug 'junegunn/vader.vim', { 'on': 'Vader', 'for': 'vader' }
``` ```
### Post-installation/update hooks `for` option is generally not needed as most plugins for specific file types
usually don't have too much code in `plugin` directory. You might want to
examine the output of `vim --startuptime` before applying the option.
### 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 +149,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 +161,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 +182,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

507
plug.vim
View File

@@ -5,7 +5,7 @@
" "
" mkdir -p ~/.vim/autoload " mkdir -p ~/.vim/autoload
" curl -fLo ~/.vim/autoload/plug.vim \ " curl -fLo ~/.vim/autoload/plug.vim \
" https://raw.github.com/junegunn/vim-plug/master/plug.vim " https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" "
" Edit your .vimrc " Edit your .vimrc
" "
@@ -68,22 +68,23 @@ let g:loaded_plug = 1
let s:cpo_save = &cpo 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.githubusercontent.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 = resolve(expand('<sfile>:p'))
let s:base_spec = { 'branch': 'master', 'frozen': 0, 'local': 0 } let s:base_spec = { 'branch': 'master', 'frozen': 0 }
let s:TYPE = { let s:TYPE = {
\ 'string': type(''), \ 'string': type(''),
\ 'list': type([]), \ 'list': 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
let home = s:path(fnamemodify(a:1, ':p')) let home = s:path(fnamemodify(expand(a:1), ':p'))
elseif exists('g:plug_home') elseif exists('g:plug_home')
let home = s:path(g:plug_home) let home = s:path(g:plug_home)
elseif !empty(&rtp) elseif !empty(&rtp)
@@ -92,37 +93,40 @@ 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')
return s:err('`git` executable not found. vim-plug requires git.')
endif
let g:plug_home = home let g:plug_home = home
let g:plugs = {} let g:plugs = {}
" 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>)
if !executable('git')
return s:err('`git` executable not found. vim-plug requires git.')
endif
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
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() function! plug#end()
if !exists('g:plugs') if !exists('g:plugs')
return s:err('Call plug#begin() first') return s:err('Call plug#begin() first')
@@ -137,20 +141,15 @@ function! plug#end()
let lod = {} let lod = {}
filetype off filetype off
" we want to make sure the plugin directories are added to rtp in the same for name in g:plugs_order
" order that they are registered with the Plug command. since the s:add_rtp
" function uses ^= to add plugin directories to the front of the rtp, we
" need to loop through the plugins in reverse
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, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for')
call s:add_rtp(s:rtp(plug)) let s:loaded[name] = 1
continue continue
endif endif
if has_key(plug, 'on') if has_key(plug, 'on')
let commands = s:to_a(plug.on) for cmd in s:to_a(plug.on)
for cmd in commands
if cmd =~ '^<Plug>.\+' if cmd =~ '^<Plug>.\+'
if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i')) if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i'))
for [mode, map_prefix, key_prefix] in for [mode, map_prefix, key_prefix] in
@@ -169,10 +168,11 @@ function! plug#end()
endif endif
if has_key(plug, 'for') if has_key(plug, 'for')
for vim in split(globpath(s:rtp(plug), 'ftdetect/**/*.vim'), '\n') let types = s:to_a(plug.for)
execute 'source '.vim if !empty(types)
endfor call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
for key in s:to_a(plug.for) endif
for key in types
if !has_key(lod, key) if !has_key(lod, key)
let lod[key] = [] let lod[key] = []
endif endif
@@ -184,12 +184,27 @@ function! plug#end()
for [key, names] in items(lod) for [key, names] in items(lod)
augroup PlugLOD augroup PlugLOD
execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s)', execute printf('autocmd FileType %s call <SID>lod_ft(%s, %s)',
\ key, string(key), string(reverse(names))) \ key, string(key), string(names))
augroup END augroup END
endfor endfor
call s:reorg_rtp() call s:reorg_rtp()
filetype plugin indent on filetype plugin indent on
syntax on if has('vim_starting')
syntax enable
else
call s:reload()
endif
endfunction
function! s:loaded_names()
return filter(copy(g:plugs_order), 'get(s:loaded, v:val, 0)')
endfunction
function! s:reload()
for name in s:loaded_names()
call s:source(s:rtp(g:plugs[name]), 'plugin/**/*.vim', 'after/plugin/**/*.vim')
endfor
endfunction endfunction
function! s:trim(str) function! s:trim(str)
@@ -238,59 +253,100 @@ function! s:err(msg)
endfunction endfunction
function! s:esc(path) function! s:esc(path)
return substitute(a:path, ' ', '\\ ', 'g') return escape(a:path, ' ')
endfunction endfunction
function! s:add_rtp(rtp) function! s:escrtp(path)
execute 'set rtp^='.s:esc(a:rtp) return escape(a:path, ' ,')
let after = globpath(a:rtp, 'after') endfunction
function! s:remove_rtp()
for name in s:loaded_names()
let rtp = s:rtp(g:plugs[name])
execute 'set rtp-='.s:escrtp(rtp)
let after = globpath(rtp, 'after')
if isdirectory(after) if isdirectory(after)
execute 'set rtp+='.s:esc(after) execute 'set rtp-='.s:escrtp(after)
endif endif
endfor
endfunction endfunction
function! s:reorg_rtp() function! s:reorg_rtp()
if !empty(s:first_rtp) if !empty(s:first_rtp)
execute 'set rtp-='.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
" &rtp is modified from outside
if exists('s:prtp') && s:prtp !=# &rtp
call s:remove_rtp()
unlet! s:middle
endif
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.',', '^,,$', ',', '')
\ . join(map(afters, 's:escrtp(v:val)'), ',')
let s:prtp = &rtp
if !empty(s:first_rtp)
execute 'set rtp^='.s:first_rtp
execute 'set rtp+='.s:last_rtp execute 'set rtp+='.s:last_rtp
endif endif
endfunction endfunction
function! s:lod(plug, types) function! plug#load(...)
let rtp = s:rtp(a:plug) if a:0 == 0
call s:add_rtp(rtp) 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([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
endfor
silent! doautocmd BufRead
return 1
endfunction
function! s:lod(names, types)
for name in a:names
let s:loaded[name] = 1
endfor
call s:reorg_rtp()
for name in a:names
let rtp = s:rtp(g:plugs[name])
for dir in a:types for dir in a:types
for vim in split(globpath(rtp, dir.'/**/*.vim'), '\n') call s:source(rtp, dir.'/**/*.vim')
execute 'source '.vim
endfor endfor
endfor endfor
endfunction endfunction
function! s:lod_ft(pat, names) function! s:lod_ft(pat, names)
for name in a:names call s:lod(a:names, ['plugin', 'after/plugin'])
call s:lod(g:plugs[name], ['plugin', 'after']) execute 'autocmd! PlugLOD FileType' a:pat
endfor
call s:reorg_rtp()
execute 'autocmd! PlugLOD FileType ' . a:pat
silent! doautocmd filetypeplugin FileType silent! doautocmd filetypeplugin FileType
silent! doautocmd filetypeindent FileType
endfunction endfunction
function! s:lod_cmd(cmd, bang, l1, l2, args, name) function! s:lod_cmd(cmd, bang, l1, l2, args, name)
execute 'delc '.a:cmd execute 'delc' a:cmd
call s:lod(g:plugs[a:name], ['plugin', 'ftdetect', 'after']) call s:lod([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) execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args)
endfunction endfunction
function! s:lod_map(map, name, prefix) function! s:lod_map(map, name, prefix)
execute 'unmap '.a:map execute 'unmap' a:map
execute 'iunmap '.a:map execute 'iunmap' a:map
call s:lod(g:plugs[a:name], ['plugin', 'ftdetect', 'after']) call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
call s:reorg_rtp()
let extra = '' let extra = ''
while 1 while 1
let c = getchar(0) let c = getchar(0)
@@ -311,9 +367,10 @@ function! s:add(repo, ...)
let repo = s:trim(a:repo) let repo = s:trim(a:repo)
let name = fnamemodify(repo, ':t:s?\.git$??') let name = fnamemodify(repo, ':t:s?\.git$??')
let spec = extend(s:infer_properties(name, repo), let spec = extend(s:infer_properties(name, repo),
\ a:0 == 1 ? s:parse_options(a:1) : copy(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[name] = 0
catch catch
return s:err(v:exception) return s:err(v:exception)
endtry endtry
@@ -341,7 +398,7 @@ endfunction
function! s:infer_properties(name, repo) function! s:infer_properties(name, repo)
let repo = a:repo let repo = a:repo
if s:is_local_plug(repo) if s:is_local_plug(repo)
let properties = { 'dir': s:dirpath(expand(repo)), 'local': 1 } return { 'dir': s:dirpath(expand(repo)) }
else else
if repo =~ ':' if repo =~ ':'
let uri = repo let uri = repo
@@ -349,32 +406,33 @@ function! s:infer_properties(name, repo)
if repo !~ '/' if repo !~ '/'
let repo = 'vim-scripts/'. repo let repo = 'vim-scripts/'. repo
endif endif
let uri = 'https://git:@github.com/' . repo . '.git' let fmt = get(g:, 'plug_url_format', 'https://git::@github.com/%s.git')
let uri = printf(fmt, repo)
endif endif
let dir = s:dirpath( fnamemodify(join([g:plug_home, a:name], '/'), ':p') ) let dir = s:dirpath( fnamemodify(join([g:plug_home, a:name], '/'), ':p') )
let properties = { 'dir': dir, 'uri': uri } return { 'dir': dir, 'uri': uri }
endif endif
return properties
endfunction endfunction
function! s:install(...) function! s:install(force, names)
call s:update_impl(0, a:000) call s:update_impl(0, a:force, a:names)
endfunction endfunction
function! s:update(...) function! s:update(force, names)
call s:update_impl(1, a:000) call s:update_impl(1, a:force, a:names)
endfunction endfunction
function! s:apply() 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
runtime! plugin/*.vim return 1
runtime! after/*.vim
silent! source $MYVIMRC
endfunction endfunction
function! s:syntax() function! s:syntax()
@@ -394,6 +452,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
@@ -414,6 +473,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)
@@ -425,22 +486,29 @@ function! s:lastline(msg)
return get(lines, -1, '') return get(lines, -1, '')
endfunction endfunction
function! s:new_window()
execute get(g:, 'plug_window', 'vertical topleft new')
endfunction
function! s:prepare() function! s:prepare()
if bufexists(s:plug_buf) if bufexists(s:plug_buf)
let winnr = bufwinnr(s:plug_buf) let winnr = bufwinnr(s:plug_buf)
if winnr < 0 if winnr < 0
vertical topleft new call s:new_window()
execute 'buffer ' . s:plug_buf execute 'buffer' s:plug_buf
else else
execute winnr . 'wincmd w' execute winnr . 'wincmd w'
endif endif
setlocal modifiable
silent %d _ silent %d _
else else
vertical topleft new call s:new_window()
nnoremap <silent> <buffer> q :if b:plug_preview==1<bar>pc<bar>endif<bar>q<cr> nnoremap <silent> <buffer> q :if b:plug_preview==1<bar>pc<bar>endif<bar>echo<bar>q<cr>
nnoremap <silent> <buffer> R :silent! call <SID>retry()<cr> nnoremap <silent> <buffer> R :silent! call <SID>retry()<cr>
nnoremap <silent> <buffer> D :PlugDiff<cr> nnoremap <silent> <buffer> D :PlugDiff<cr>
nnoremap <silent> <buffer> S :PlugStatus<cr> nnoremap <silent> <buffer> S :PlugStatus<cr>
nnoremap <silent> <buffer> U :call <SID>status_update()<cr>
xnoremap <silent> <buffer> U :call <SID>status_update()<cr>
nnoremap <silent> <buffer> ]] :silent! call <SID>section('')<cr> nnoremap <silent> <buffer> ]] :silent! call <SID>section('')<cr>
nnoremap <silent> <buffer> [[ :silent! call <SID>section('b')<cr> nnoremap <silent> <buffer> [[ :silent! call <SID>section('b')<cr>
let b:plug_preview = -1 let b:plug_preview = -1
@@ -448,7 +516,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
@@ -462,18 +532,19 @@ function! s:assign_name()
let name = printf('%s (%s)', prefix, idx) let name = printf('%s (%s)', prefix, idx)
let idx = idx + 1 let idx = idx + 1
endwhile endwhile
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
@@ -488,7 +559,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
@@ -505,16 +577,18 @@ endfunction
function! s:finish(pull) function! s:finish(pull)
call append(3, '- Finishing ... ') call append(3, '- Finishing ... ')
redraw redraw
call s:apply() call plug#helptags()
call s:syntax() call plug#end()
call setline(4, getline(4) . 'Done!') call setline(4, getline(4) . 'Done!')
normal! gg normal! gg
call s:syntax()
redraw redraw
let msgs = [] let msgs = []
if !empty(s:prev_update.errors) if !empty(s:prev_update.errors)
call add(msgs, "Press 'R' to retry.") call add(msgs, "Press 'R' to retry.")
endif endif
if a:pull if a:pull && !empty(filter(getline(5, '$'),
\ "v:val =~ '^- ' && stridx(v:val, 'Already up-to-date') < 0"))
call add(msgs, "Press 'D' to see the updated changes.") call add(msgs, "Press 'D' to see the updated changes.")
endif endif
echo join(msgs, ' ') echo join(msgs, ' ')
@@ -524,7 +598,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
@@ -536,7 +610,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]*$') ?
@@ -553,17 +627,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 len = len(g:plugs)
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
@@ -574,9 +653,9 @@ function! s:update_impl(pull, args) abort
catch catch
let lines = getline(4, '$') let lines = getline(4, '$')
let printed = {} let printed = {}
silent 4,$d silent 4,$d _
for line in lines for line in lines
let name = get(matchlist(line, '^. \([^:]\+\):'), 1, '') let name = matchstr(line, '^. \zs[^:]\+\ze:')
if empty(name) || !has_key(printed, name) if empty(name) || !has_key(printed, name)
call append('$', line) call append('$', line)
if !empty(name) if !empty(name)
@@ -593,10 +672,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")'))
if len(g:plugs) > len
call plug#end()
endif
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
@@ -619,12 +695,12 @@ function! s:update_serial(pull, todo)
for [name, spec] in items(todo) for [name, spec] in items(todo)
let done[name] = 1 let done[name] = 1
if isdirectory(spec.dir) if isdirectory(spec.dir)
execute 'cd '.s:esc(spec.dir) execute 'cd' s:esc(spec.dir)
let [valid, msg] = s:git_valid(spec, 0, 0) let [valid, msg] = s:git_valid(spec, 0, 0)
if valid if valid
let result = a:pull ? let result = a:pull ?
\ s:system( \ s:system(
\ printf('git checkout -q %s 2>&1 && git pull origin %s 2>&1 && git submodule update --init --recursive 2>&1', \ printf('git checkout -q %s 2>&1 && git pull --no-rebase origin %s 2>&1 && git submodule update --init --recursive 2>&1',
\ s:shellesc(spec.branch), s:shellesc(spec.branch))) : 'Already installed' \ s:shellesc(spec.branch), s:shellesc(spec.branch))) : 'Already installed'
let error = a:pull ? v:shell_error != 0 : 0 let error = a:pull ? v:shell_error != 0 : 0
else else
@@ -674,6 +750,20 @@ function! s:update_parallel(pull, todo, threads)
%["#{arg.gsub('"', '\"')}"] %["#{arg.gsub('"', '\"')}"]
end end
def killall pid
pids = [pid]
unless `which pgrep 2> /dev/null`.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 'thread'
require 'fileutils' require 'fileutils'
require 'timeout' require 'timeout'
@@ -681,7 +771,7 @@ function! s:update_parallel(pull, todo, threads)
iswin = VIM::evaluate('s:is_win').to_i == 1 iswin = VIM::evaluate('s:is_win').to_i == 1
pull = VIM::evaluate('a:pull').to_i == 1 pull = VIM::evaluate('a:pull').to_i == 1
base = VIM::evaluate('g:plug_home') 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)') limit = VIM::evaluate('get(g:, "plug_timeout", 60)')
tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1 tries = VIM::evaluate('get(g:, "plug_retries", 2)') + 1
nthr = VIM::evaluate('a:threads').to_i nthr = VIM::evaluate('a:threads').to_i
@@ -728,7 +818,7 @@ function! s:update_parallel(pull, todo, threads)
logh.call logh.call
end end
} }
bt = proc { |cmd, name, type| bt = proc { |cmd, name, type, cleanup|
tried = timeout = 0 tried = timeout = 0
begin begin
tried += 1 tried += 1
@@ -756,19 +846,10 @@ function! s:update_parallel(pull, todo, threads)
[$? == 0, data.chomp] [$? == 0, data.chomp]
rescue Timeout::Error, Interrupt => e rescue Timeout::Error, Interrupt => e
if fd && !fd.closed? if fd && !fd.closed?
pids = [fd.pid] killall 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 }
fd.close fd.close
end end
cleanup.call if cleanup
if e.is_a?(Timeout::Error) && tried < tries if e.is_a?(Timeout::Error) && tried < tries
3.downto(1) do |countdown| 3.downto(1) do |countdown|
s = countdown > 1 ? 's' : '' s = countdown > 1 ? 's' : ''
@@ -817,7 +898,7 @@ function! s:update_parallel(pull, todo, threads)
ok, result = ok, result =
if exists if exists
dir = esc dir dir = esc dir
ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil ret, data = bt.call "#{cd} #{dir} && git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url", nil, nil, nil
current_uri = data.lines.to_a.last current_uri = data.lines.to_a.last
if !ret if !ret
if data =~ /^Interrupted|^Timeout/ if data =~ /^Interrupted|^Timeout/
@@ -825,14 +906,14 @@ function! s:update_parallel(pull, todo, threads)
else else
[false, [data.chomp, "PlugClean required."].join($/)] [false, [data.chomp, "PlugClean required."].join($/)]
end end
elsif current_uri.sub(/git:@/, '') != uri.sub(/git:@/, '') elsif current_uri.sub(/git::?@/, '') != uri.sub(/git::?@/, '')
[false, ["Invalid URI: #{current_uri}", [false, ["Invalid URI: #{current_uri}",
"Expected: #{uri}", "Expected: #{uri}",
"PlugClean required."].join($/)] "PlugClean required."].join($/)]
else else
if pull if pull
log.call name, 'Updating ...', :update 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 bt.call "#{cd} #{dir} && git checkout -q #{branch} 2>&1 && (git pull --no-rebase origin #{branch} #{progress} 2>&1 && #{subm})", name, :update, nil
else else
[true, skip] [true, skip]
end end
@@ -840,7 +921,9 @@ function! s:update_parallel(pull, todo, threads)
else else
d = esc dir.sub(%r{[\\/]+$}, '') d = esc dir.sub(%r{[\\/]+$}, '')
log.call name, 'Installing ...', :install log.call name, 'Installing ...', :install
bt.call "(git clone #{progress} --recursive #{uri} -b #{branch} #{d} 2>&1 && cd #{esc dir} && #{subm})", name, :install bt.call "(git clone #{progress} --recursive #{uri} -b #{branch} #{d} 2>&1 && cd #{esc dir} && #{subm})", name, :install, proc {
FileUtils.rm_rf dir
}
end end
mtx.synchronize { VIM::command("let s:prev_update.new['#{name}'] = 1") } if !exists && ok mtx.synchronize { VIM::command("let s:prev_update.new['#{name}'] = 1") } if !exists && ok
log.call name, result, ok log.call name, result, ok
@@ -868,8 +951,8 @@ function! s:progress_bar(line, bar, total)
endfunction endfunction
function! s:compare_git_uri(a, b) function! s:compare_git_uri(a, b)
let a = substitute(a:a, 'git:@', '', '') let a = substitute(a:a, 'git:\{1,2}@', '', '')
let b = substitute(a:b, 'git:@', '', '') let b = substitute(a:b, 'git:\{1,2}@', '', '')
return a ==# b return a ==# b
endfunction endfunction
@@ -895,7 +978,7 @@ function! s:git_valid(spec, check_branch, cd)
let ret = 1 let ret = 1
let msg = 'OK' let msg = 'OK'
if isdirectory(a:spec.dir) if isdirectory(a:spec.dir)
if a:cd | execute 'cd ' . s:esc(a:spec.dir) | endif if a:cd | execute 'cd' s:esc(a:spec.dir) | endif
let result = split(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url'), '\n') let result = split(s:system('git rev-parse --abbrev-ref HEAD 2>&1 && git config remote.origin.url'), '\n')
let remote = result[-1] let remote = result[-1]
if v:shell_error if v:shell_error
@@ -986,49 +1069,45 @@ function! s:clean(force)
endfunction endfunction
function! s:upgrade() function! s:upgrade()
if executable('curl') let new = s:me . '.new'
let mee = s:shellesc(s:me)
let new = s:shellesc(s:me . '.new')
echo 'Downloading '. s:plug_source echo 'Downloading '. s:plug_source
redraw redraw
let mv = s:is_win ? 'move /Y' : 'mv -f' try
let cp = s:is_win ? 'copy /Y' : 'cp -f' if executable('curl')
call system(printf( let output = system(printf('curl -fLo %s %s', s:shellesc(new), s:plug_source))
\ 'curl -fLo %s %s && '.cp.' %s %s.old && '.mv.' %s %s', if v:shell_error
\ new, s:plug_source, mee, mee, new, mee)) throw get(split(output, '\n'), -1, v:shell_error)
if v:shell_error == 0
unlet g:loaded_plug
echo 'Downloaded '. s:plug_source
return 1
else
return s:err('Error upgrading vim-plug')
endif endif
elseif has('ruby') elseif has('ruby')
echo 'Downloading '. s:plug_source
ruby << EOF ruby << EOF
require 'open-uri' require 'open-uri'
require 'fileutils' File.open(VIM::evaluate('new'), 'w') do |f|
me = VIM::evaluate('s:me')
old = me + '.old'
new = me + '.new'
File.open(new, 'w') do |f|
f << open(VIM::evaluate('s:plug_source')).read f << open(VIM::evaluate('s:plug_source')).read
end end
FileUtils.cp me, old
File.rename new, me
EOF EOF
unlet g:loaded_plug
echo 'Downloaded '. s:plug_source
return 1
else else
return s:err('curl executable or ruby support not found') return s:err('curl executable or ruby support not found')
endif endif
catch
return s:err('Error upgrading vim-plug: '. v:exception)
endtry
if readfile(s:me) ==# readfile(new)
echo 'vim-plug is up-to-date'
silent! call delete(new)
return 0
else
call rename(s:me, s:me . '.old')
call rename(new, s:me)
unlet g:loaded_plug
echo 'vim-plug is upgraded'
return 1
endif
endfunction endfunction
function! s:upgrade_specs() function! s:upgrade_specs()
for spec in values(g:plugs) for spec in values(g:plugs)
let spec.frozen = get(spec, 'frozen', 0) let spec.frozen = get(spec, 'frozen', 0)
let spec.local = get(spec, 'local', 0)
endfor endfor
endfunction endfunction
@@ -1038,6 +1117,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')
@@ -1055,6 +1135,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, name, -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
@@ -1062,6 +1147,36 @@ 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, or 'U' to update"
nnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
xnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
end
endfunction
function! s:extract_name(str, prefix, suffix)
return matchstr(a:str, '^'.a:prefix.' \zs[^:]\+\ze:.*'.a:suffix.'$')
endfunction
function! s:status_load(lnum)
let line = getline(a:lnum)
let name = s:extract_name(line, '-', '(not loaded)')
if !empty(name)
call plug#load(name)
setlocal modifiable
call setline(a:lnum, substitute(line, ' (not loaded)$', '', ''))
setlocal nomodifiable
endif
endfunction
function! s:status_update() range
let lines = getline(a:firstline, a:lastline)
let names = filter(map(lines, 's:extract_name(v:val, "[x-]", "")'), '!empty(v:val)')
if !empty(names)
echo
execute 'PlugUpdate' join(names)
endif
endfunction endfunction
function! s:is_preview_window_open() function! s:is_preview_window_open()
@@ -1073,34 +1188,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 endif
let lnum -= 1
let line = getline(lnum) let name = s:find_name(line('.'))
let name = matchstr(line, '\(^- \)\@<=[^:]\+') if empty(name) || !has_key(g:plugs, name) || !isdirectory(g:plugs[name].dir)
if !empty(name) return
let dir = g:plugs[name].dir endif
if isdirectory(dir)
execute 'cd '.s:esc(dir) execute 'pedit' sha
execute 'pedit '.sha
wincmd P wincmd P
setlocal filetype=git buftype=nofile nobuflisted setlocal filetype=git buftype=nofile nobuflisted
execute 'silent read !git show '.sha execute 'cd' s:esc(g:plugs[name].dir)
normal! ggdd execute 'silent read !git show' sha
wincmd p
cd - cd -
endif normal! gg"_dd
break wincmd p
endif
endwhile
endif
endfunction endfunction
function! s:section(flags) function! s:section(flags)
@@ -1119,7 +1243,7 @@ function! s:diff()
continue continue
endif endif
execute 'cd '.s:esc(v.dir) execute 'cd' s:esc(v.dir)
let diff = system('git log --pretty=format:"%h %s (%cr)" "HEAD...HEAD@{1}"') let diff = system('git log --pretty=format:"%h %s (%cr)" "HEAD...HEAD@{1}"')
if !v:shell_error && !empty(diff) if !v:shell_error && !empty(diff)
call append(1, '') call append(1, '')
@@ -1134,11 +1258,42 @@ 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 endfunction
let s:first_rtp = s:esc(get(split(&rtp, ','), 0, '')) function! s:revert()
let s:last_rtp = s:esc(get(split(&rtp, ','), -1, '')) 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
function! s:split_rtp()
return split(&rtp, '\\\@<!,')
endfunction
let s:first_rtp = s:escrtp(get(s:split_rtp(), 0, ''))
let s:last_rtp = s:escrtp(get(s: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

@@ -14,8 +14,40 @@ if [ ! -d fzf-staged ]; then
git clone https://github.com/junegunn/fzf.git fzf-staged git clone https://github.com/junegunn/fzf.git fzf-staged
fi fi
make_dirs() {
mkdir -p "$1"
cd "$1"
mkdir -p autoload colors ftdetect ftplugin indent plugin syntax
for d in *; do
[ -d $d ] || continue
cat > $d/xxx.vim << EOF
" echom expand('<sfile>')
let g:total_order = get(g:, 'total_order', [])
let g:$2 = get(g:, '$2', [])
let s:name = join(filter(['$2', '${1:4}', '$d'], '!empty(v:val)'), '/')
call add(g:$2, s:name)
call add(g:total_order, s:name)
EOF
done
cd - > /dev/null
}
make_dirs xxx/ xxx
make_dirs xxx/after xxx
mkdir -p xxx/doc
cat > xxx/doc/xxx.txt << DOC
hello *xxx*
DOC
make_dirs yyy/ yyy
make_dirs yyy/after 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

@@ -1,5 +1,5 @@
Execute (Initialize test environment): Execute (Initialize test environment):
Save &rtp, g:plugs, g:plug_home, $MYVIMRC Save &rtp, g:plugs, g:plug_home, g:plug_window
let first_rtp = split(&rtp, ',')[0] let first_rtp = split(&rtp, ',')[0]
let last_rtp = split(&rtp, ',')[-1] let last_rtp = split(&rtp, ',')[-1]
@@ -11,8 +11,7 @@ Execute (Initialize test environment):
execute 'set rtp^='.plug execute 'set rtp^='.plug
let basertp = &rtp let basertp = &rtp
unlet! g:plugs unlet! g:plugs g:plug_home g:plug_window
unlet! g:plug_home
set t_Co=256 set t_Co=256
colo default colo default
@@ -28,15 +27,22 @@ Execute (Initialize test environment):
endfunction endfunction
function! AssertExpect(bang, pat, cnt) function! AssertExpect(bang, pat, cnt)
let op = a:bang ? '==' : '=~' let op = a:bang ? '==#' : '=~#'
AssertEqual a:cnt, len(filter(getline(1, '$'), "v:val ".op." '".a:pat."'")) AssertEqual a:cnt, len(filter(getline(1, '$'), "v:val ".op." '".a:pat."'"))
endfunction endfunction
command! -nargs=+ -bang AssertExpect call AssertExpect('<bang>' == '!', <args>) command! -nargs=+ -bang AssertExpect call AssertExpect('<bang>' == '!', <args>)
let g:vimrc_reloaded = 0 function! EnsureLoaded()
let vimrc = tempname() if has('vim_starting')
call writefile(['let g:vimrc_reloaded += 1'], vimrc) runtime! plugin/**/*.vim
let $MYVIMRC = vimrc endif
endfunction
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
@@ -74,7 +80,7 @@ Execute (Subsequent plug#begin() calls will reuse g:plug_home):
Execute (Test Plug command): Execute (Test Plug command):
" Git repo with branch " Git repo with branch
Plug 'junegunn/seoul256.vim', 'yes-t_co' Plug 'junegunn/seoul256.vim', 'yes-t_co'
AssertEqual 'https://git:@github.com/junegunn/seoul256.vim.git', g:plugs['seoul256.vim'].uri 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 join([temp_plugged, 'seoul256.vim/'], '/'), g:plugs['seoul256.vim'].dir
AssertEqual 'yes-t_co', g:plugs['seoul256.vim'].branch AssertEqual 'yes-t_co', g:plugs['seoul256.vim'].branch
@@ -83,7 +89,7 @@ Execute (Test Plug command):
" Git repo with tag " Git repo with tag
Plug 'junegunn/goyo.vim', '1.5.2' Plug 'junegunn/goyo.vim', '1.5.2'
AssertEqual 'https://git:@github.com/junegunn/goyo.vim.git', g:plugs['goyo.vim'].uri 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 join([temp_plugged, 'goyo.vim/'], '/'), g:plugs['goyo.vim'].dir
AssertEqual '1.5.2', g:plugs['goyo.vim'].branch AssertEqual '1.5.2', g:plugs['goyo.vim'].branch
@@ -98,7 +104,7 @@ Execute (Test Plug command):
" vim-scripts/ " vim-scripts/
Plug 'beauty256' Plug 'beauty256'
AssertEqual 'https://git:@github.com/vim-scripts/beauty256.git', g:plugs.beauty256.uri AssertEqual 'https://git::@github.com/vim-scripts/beauty256.git', g:plugs.beauty256.uri
AssertEqual 'master', g:plugs.beauty256.branch AssertEqual 'master', g:plugs.beauty256.branch
AssertEqual 4, len(g:plugs) AssertEqual 4, len(g:plugs)
@@ -133,7 +139,6 @@ Execute (Yet, plugins are not available):
Execute (PlugInstall): Execute (PlugInstall):
PlugInstall PlugInstall
AssertEqual 1, g:vimrc_reloaded
q q
Execute (Plugin available after installation): Execute (Plugin available after installation):
@@ -167,7 +172,6 @@ Expect:
Execute (PlugUpdate to set the right branch): Execute (PlugUpdate to set the right branch):
PlugUpdate PlugUpdate
call PlugStatusSorted() call PlugStatusSorted()
AssertEqual 2, g:vimrc_reloaded
Expect: Expect:
- goyo.vim: OK - goyo.vim: OK
@@ -200,8 +204,8 @@ Execute (PlugStatus):
call PlugStatusSorted() call PlugStatusSorted()
Expect: Expect:
Expected: https://git:@github.com/junegunn.choi/seoul256.vim.git Expected: https://git::@github.com/junegunn.choi/seoul256.vim.git
Invalid URI: https://git:@github.com/junegunn/seoul256.vim.git Invalid URI: https://git::@github.com/junegunn/seoul256.vim.git
PlugClean required. PlugClean required.
- vim-emoji: OK - vim-emoji: OK
Finished. 1 error(s). Finished. 1 error(s).
@@ -234,7 +238,7 @@ Execute (PlugStatus):
call PlugStatusSorted() call PlugStatusSorted()
Expect: Expect:
Expected: https://git:@github.com/junegunn/vim-emoji.git Expected: https://git::@github.com/junegunn/vim-emoji.git
Invalid URI: https://bitbucket.org/junegunn/vim-emoji.git Invalid URI: https://bitbucket.org/junegunn/vim-emoji.git
Not found. Try PlugInstall. Not found. Try PlugInstall.
PlugClean required. PlugClean required.
@@ -254,7 +258,6 @@ Execute (PlugClean! to remove vim-emoji):
Execute (PlugUpdate to install both again): Execute (PlugUpdate to install both again):
PlugUpdate PlugUpdate
AssertExpect '^- [^:]*:', 2 AssertExpect '^- [^:]*:', 2
AssertEqual 3, g:vimrc_reloaded
Assert !empty(globpath(&rtp, 'colors/seoul256.vim')), 'seoul256.vim should be found' Assert !empty(globpath(&rtp, 'colors/seoul256.vim')), 'seoul256.vim should be found'
Assert !empty(globpath(&rtp, 'autoload/emoji.vim')), 'vim-emoji should be found' Assert !empty(globpath(&rtp, 'autoload/emoji.vim')), 'vim-emoji should be found'
q q
@@ -262,7 +265,6 @@ Execute (PlugUpdate to install both again):
Execute (PlugUpdate only to find out plugins are up-to-date, D key to check): Execute (PlugUpdate only to find out plugins are up-to-date, D key to check):
PlugUpdate PlugUpdate
AssertExpect 'Already up-to-date', 2 AssertExpect 'Already up-to-date', 2
AssertEqual 4, g:vimrc_reloaded
normal D normal D
AssertEqual 'No updates.', getline(1) AssertEqual 'No updates.', getline(1)
q q
@@ -310,6 +312,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
@@ -320,6 +329,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
@@ -333,8 +343,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
@@ -384,9 +394,11 @@ Given (Unaligned code):
aa=2 aa=2
Execute (Check installed plugins): Execute (Check installed plugins):
call EnsureLoaded()
Assert exists(':FNR'), 'FNR command should be found' 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(':RedisExecute'), 'RedisExecute command still should not be found'
Assert exists(':EasyAlign'), 'EasyAlign command should be found'
%EasyAlign= %EasyAlign=
Expect (Aligned code): Expect (Aligned code):
@@ -510,15 +522,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
@@ -625,6 +637,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):
@@ -638,11 +658,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()
@@ -656,11 +684,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`
@@ -683,19 +726,298 @@ Execute (Using custom dir):
q q
Assert isdirectory(g:plugs['vim-easy-align'].dir) Assert isdirectory(g:plugs['vim-easy-align'].dir)
Execute (Cleanup): **********************************************************************
call system('rm -rf '.temp_plugged) ~ On-demand loading load order
call rename('fzf', 'fzf-staged') **********************************************************************
Before (Clear global vars):
let g:xxx = []
set rtp-=$PWD/xxx/
set rtp-=$PWD/xxx/after
unlet g:plugs Execute (Immediate loading):
unlet g:plug_home call plug#begin()
unlet g:vimrc_reloaded Plug '$PWD/xxx'
unlet temp_plugged vader plug basertp save_rtp repo lnum fzf out call plug#end()
delf PlugStatusSorted
delf AssertExpect " FIXME:
delf PlugUpdated " Different result when Vader is run from commandline with `-c` option
delc AssertExpect Log g:xxx
unmap / if has('vim_starting')
unmap ? AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect'], g:xxx
else
AssertEqual ['xxx/plugin', 'xxx/after/plugin', 'xxx/ftdetect', 'xxx/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 ['xxx/ftdetect', 'xxx/after/ftdetect', 'xxx/plugin', 'xxx/after/plugin'], g:xxx
setf xxx
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect', 'xxx/plugin', 'xxx/after/plugin', 'xxx/ftplugin', 'xxx/after/ftplugin', 'xxx/indent', 'xxx/after/indent', 'xxx/syntax', 'xxx/after/syntax'], g:xxx
Execute (Filetype-based on-demand loading):
call plug#begin()
Plug '$PWD/xxx', { 'for': 'xxx' }
call plug#end()
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect'], g:xxx
setf xxx
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect', 'xxx/plugin', 'xxx/after/plugin', 'xxx/ftplugin', 'xxx/after/ftplugin', 'xxx/indent', 'xxx/after/indent', 'xxx/syntax', 'xxx/after/syntax'], g:xxx
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
**********************************************************************
~ g:plug_window
**********************************************************************
Execute (Open plug window in a new tab):
" Without g:plug_window, plug window is open on the left split
let tabnr = tabpagenr()
PlugStatus
AssertEqual tabnr, tabpagenr()
AssertEqual 1, winnr()
" PlugStatus again inside the window should not change the view
normal S
AssertEqual tabnr, tabpagenr()
AssertEqual 1, winnr()
q
" Define g:plug_window so that plug window is open in a new tab
let g:plug_window = 'tabnew'
PlugStatus
AssertNotEqual tabnr, tabpagenr()
" PlugStatus again inside the window should not change the view
let tabnr = tabpagenr()
normal S
AssertEqual tabnr, tabpagenr()
q
unlet g:plug_window
**********************************************************************
~ g:plug_url_format
**********************************************************************
Execute (Using g:plug_url_format):
call plug#begin()
let g:plug_url_format = 'git@bitbucket.org:%s.git'
Plug 'junegunn/seoul256.vim'
let g:plug_url_format = 'git@bitsocket.org:%s.git'
Plug 'beauty256'
AssertEqual 'git@bitbucket.org:junegunn/seoul256.vim.git', g:plugs['seoul256.vim'].uri
AssertEqual 'git@bitsocket.org:vim-scripts/beauty256.git', g:plugs['beauty256'].uri
unlet g:plug_url_format
**********************************************************************
~ U
**********************************************************************
Execute (Plug block):
call plug#begin()
Plug 'junegunn/vim-easy-align'
Plug 'junegunn/vim-emoji'
call plug#end()
Execute (Update plugin with U key in normal mode):
PlugStatus
/emoji
normal U
Log getline(1, '$')
AssertExpect 'Updated', 1
AssertExpect 'vim-emoji', 1
AssertExpect 'vim-easy-align', 0
AssertExpect! '[=]', 1
" From PlugInstall screen
PlugInstall
/easy-align
normal U
AssertExpect 'Updated', 1
AssertExpect 'vim-emoji', 0
AssertExpect 'vim-easy-align', 1
AssertExpect! '[=]', 1
q
Execute (Update plugins with U key in visual mode):
silent! call system('rm -rf '.g:plugs['vim-easy-align'].dir)
PlugStatus
normal VGU
Log getline(1, '$')
AssertExpect 'Updated', 1
AssertExpect 'vim-emoji', 1
AssertExpect 'vim-easy-align', 1
AssertExpect! '[==]', 1
" From PlugUpdate screen
normal VGU
Log getline(1, '$')
AssertExpect 'Updated', 1
AssertExpect 'vim-emoji', 1
AssertExpect 'vim-easy-align', 1
AssertExpect! '[==]', 1
q
**********************************************************************
Execute (plug#begin should expand env vars):
AssertNotEqual '$HOME/.emacs/plugged', expand('$HOME/.emacs/plugged')
call plug#begin('$HOME/.emacs/plugged')
AssertEqual expand('$HOME/.emacs/plugged'), g:plug_home
**********************************************************************
Execute (Plug directory with comma):
call plug#begin(temp_plugged . '/p,l,u,g,g,e,d')
Plug 'junegunn/vim-emoji'
call plug#end()
Log &rtp
PlugInstall
q
let found = filter(split(globpath(&rtp, 'README.md'), '\n'), 'v:val =~ ","')
Log found
AssertEqual 1, len(found)
**********************************************************************
Execute (Strict load order):
let g:total_order = []
call plug#begin()
Plug '$PWD/xxx'
Plug '$PWD/yyy', { 'for': ['xxx'] }
call plug#end()
call EnsureLoaded()
setf xxx
Log 'Case 1: ' . &rtp
AssertEqual ['yyy/ftdetect', 'yyy/after/ftdetect', 'xxx/ftdetect', 'xxx/after/ftdetect'], g:total_order[0:3]
Assert index(g:total_order, 'xxx/plugin') < index(g:total_order, 'yyy/plugin')
Assert index(g:total_order, 'xxx/after/plugin') < index(g:total_order, 'yyy/after/plugin')
let len = len(split(&rtp, ','))
let g:total_order = []
call plug#begin()
Plug '$PWD/xxx', { 'for': ['xxx'] }
Plug '$PWD/yyy'
call plug#end()
call EnsureLoaded()
set rtp^=manually-prepended
set rtp+=manually-appended
setf xxx
Log 'Case 2: ' . &rtp
AssertEqual 'manually-prepended', split(&rtp, ',')[3]
AssertEqual 'manually-appended', split(&rtp, ',')[-4]
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect', 'yyy/ftdetect', 'yyy/after/ftdetect'], g:total_order[0:3]
Assert index(g:total_order, 'yyy/plugin') < index(g:total_order, 'xxx/plugin')
Assert index(g:total_order, 'yyy/after/plugin') < index(g:total_order, 'xxx/after/plugin')
AssertEqual len + 2, len(split(&rtp, ','))
let g:total_order = []
call plug#begin()
Plug '$PWD/xxx', { 'for': ['xxx'] }
Plug '$PWD/yyy', { 'for': ['xxx'] }
call plug#end()
call EnsureLoaded()
setf xxx
Log 'Case 3: ' . &rtp
AssertEqual ['xxx/ftdetect', 'xxx/after/ftdetect', 'yyy/ftdetect', 'yyy/after/ftdetect'], g:total_order[0:3]
Assert index(g:total_order, 'xxx/plugin') < index(g:total_order, 'yyy/plugin')
Assert index(g:total_order, 'xxx/after/plugin') < index(g:total_order, 'yyy/after/plugin')
AssertEqual len + 2, len(split(&rtp, ','))
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 g:plug_url_format
silent! unlet temp_plugged vader plug basertp save_rtp repo lnum fzf out tabnr found len
silent! delf PlugStatusSorted
silent! delf AssertExpect
silent! delf PlugUpdated
silent! delf EnsureLoaded
silent! delc AssertExpect
silent! unmap /
silent! unmap ?
Restore Restore