8 Commits
0.5.3 ... 0.5.5

Author SHA1 Message Date
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
4 changed files with 243 additions and 56 deletions

View File

@@ -96,6 +96,10 @@ Reload .vimrc and `:PlugInstall` to install plugins.
- `S` - `PlugStatus`
- `R` - Retry failed update or installation tasks
- `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

177
plug.vim
View File

@@ -69,7 +69,7 @@ let s:cpo_save = &cpo
set cpo&vim
let s:plug_source = 'https://raw.github.com/junegunn/vim-plug/master/plug.vim'
let s:plug_buf = -1
let s:plug_buf = get(s:, 'plug_buf', -1)
let s:mac_gui = has('gui_macvim') && has('gui_running')
let s:is_win = has('win32') || has('win64')
let s:me = expand('<sfile>:p')
@@ -80,6 +80,7 @@ let s:TYPE = {
\ 'dict': type({}),
\ 'funcref': type(function('call'))
\ }
let s:loaded = get(s:, 'loaded', {})
function! plug#begin(...)
if a:0 > 0
@@ -92,10 +93,6 @@ function! plug#begin(...)
return s:err('Unable to determine plug home. Try calling plug#begin() with a path argument.')
endif
if !executable('git')
return s:err('`git` executable not found. vim-plug requires git.')
endif
let g:plug_home = home
let g:plugs = {}
" we want to keep track of the order plugins where registered.
@@ -106,7 +103,10 @@ function! plug#begin(...)
endfunction
function! s:define_commands()
command! -nargs=+ -bar Plug call s:add(<args>)
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>' == '!')
@@ -148,9 +148,8 @@ function! plug#end()
" need to loop through the plugins in reverse
for name in reverse(copy(g:plugs_order))
let plug = g:plugs[name]
if !has_key(plug, 'on') && !has_key(plug, 'for')
let rtp = s:rtp(plug)
call s:add_rtp(rtp)
if get(s:loaded, plug.dir, 0) || !has_key(plug, 'on') && !has_key(plug, 'for')
let rtp = s:add_rtp(plug)
if reload
call s:source(rtp, 'plugin/**/*.vim', 'after/plugin/**/*.vim')
endif
@@ -177,8 +176,11 @@ function! plug#end()
endif
if has_key(plug, 'for')
call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim')
for key in s:to_a(plug.for)
let types = 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)
let lod[key] = []
endif
@@ -247,12 +249,15 @@ function! s:esc(path)
return substitute(a:path, ' ', '\\ ', 'g')
endfunction
function! s:add_rtp(rtp)
execute 'set rtp^='.s:esc(a:rtp)
let after = globpath(a:rtp, 'after')
function! s:add_rtp(plug)
let rtp = s:rtp(a:plug)
execute 'set rtp^='.s:esc(rtp)
let after = globpath(rtp, 'after')
if isdirectory(after)
execute 'set rtp+='.s:esc(after)
endif
let s:loaded[a:plug.dir] = 1
return rtp
endfunction
function! s:reorg_rtp()
@@ -266,9 +271,28 @@ function! s:reorg_rtp()
endif
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)
let rtp = s:rtp(a:plug)
call s:add_rtp(rtp)
let rtp = s:add_rtp(a:plug)
for dir in a:types
call s:source(rtp, dir.'/**/*.vim')
endfor
@@ -319,6 +343,7 @@ function! s:add(repo, ...)
\ a:0 == 1 ? s:parse_options(a:1) : s:base_spec)
let g:plugs[name] = spec
let g:plugs_order += [name]
let s:loaded[spec.dir] = 0
catch
return s:err(v:exception)
endtry
@@ -354,7 +379,7 @@ function! s:infer_properties(name, repo)
if repo !~ '/'
let repo = 'vim-scripts/'. repo
endif
let uri = 'https://git:@github.com/' . repo . '.git'
let uri = 'https://git::@github.com/' . repo . '.git'
endif
let dir = s:dirpath( fnamemodify(join([g:plug_home, a:name], '/'), ':p') )
return { 'dir': dir, 'uri': uri }
@@ -369,13 +394,17 @@ function! s:update(force, ...)
call s:update_impl(1, a:force, a:000)
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)
let docd = join([spec.dir, 'doc'], '/')
if isdirectory(docd)
silent! execute 'helptags '. s:esc(docd)
endif
endfor
return 1
endfunction
function! s:syntax()
@@ -395,6 +424,7 @@ function! s:syntax()
syn match plugCommit /^ [0-9a-z]\{7} .*/ contains=plugRelDate,plugSha
syn match plugSha /\(^ \)\@<=[0-9a-z]\{7}/ contained
syn match plugRelDate /([^)]*)$/ contained
syn match plugNotLoaded /(not loaded)$/
syn match plugError /^x.*/
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
hi def link plug1 Title
@@ -415,6 +445,8 @@ function! s:syntax()
hi def link plugError Error
hi def link plugRelDate Comment
hi def link plugSha Identifier
hi def link plugNotLoaded Comment
endfunction
function! s:lpad(str, len)
@@ -435,6 +467,7 @@ function! s:prepare()
else
execute winnr . 'wincmd w'
endif
setlocal modifiable
silent %d _
else
vertical topleft new
@@ -449,7 +482,9 @@ function! s:prepare()
call s:assign_name()
endif
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
call s:syntax()
endfunction
@@ -508,7 +543,7 @@ endfunction
function! s:finish(pull)
call append(3, '- Finishing ... ')
redraw
call s:helptags()
call plug#helptags()
call plug#end()
call setline(4, getline(4) . 'Done!')
normal! gg
@@ -835,7 +870,7 @@ function! s:update_parallel(pull, todo, threads)
else
[false, [data.chomp, "PlugClean required."].join($/)]
end
elsif current_uri.sub(/git:@/, '') != uri.sub(/git:@/, '')
elsif current_uri.sub(/git::?@/, '') != uri.sub(/git::?@/, '')
[false, ["Invalid URI: #{current_uri}",
"Expected: #{uri}",
"PlugClean required."].join($/)]
@@ -878,8 +913,8 @@ function! s:progress_bar(line, bar, total)
endfunction
function! s:compare_git_uri(a, b)
let a = substitute(a:a, 'git:@', '', '')
let b = substitute(a:b, 'git:@', '', '')
let a = substitute(a:a, 'git:\{1,2}@', '', '')
let b = substitute(a:b, 'git:\{1,2}@', '', '')
return a ==# b
endfunction
@@ -1048,6 +1083,7 @@ function! s:status()
call append(1, '')
let ecnt = 0
let unloaded = 0
let [cnt, total] = [0, len(g:plugs)]
for [name, spec] in items(g:plugs)
if has_key(spec, 'uri')
@@ -1065,6 +1101,11 @@ function! s:status()
endif
let cnt += 1
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 append(3, s:format_message(valid, name, msg))
normal! 2G
@@ -1072,6 +1113,24 @@ function! s:status()
endfor
call setline(1, 'Finished. '.ecnt.' error(s).')
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
function! s:is_preview_window_open()
@@ -1083,34 +1142,43 @@ function! s:is_preview_window_open()
return 0
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()
if b:plug_preview < 0
let b:plug_preview = !s:is_preview_window_open()
endif
let sha = matchstr(getline('.'), '\(^ \)\@<=[0-9a-z]\{7}')
if !empty(sha)
let lnum = line('.')
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
if empty(sha)
return
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
function! s:section(flags)
@@ -1144,7 +1212,28 @@ function! s:diff()
call setline(1, cnt == 0 ? 'No updates.' : 'Last update:')
nnoremap <silent> <buffer> <cr> :silent! call <SID>preview_commit()<cr>
nnoremap <silent> <buffer> X :call <SID>revert()<cr>
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
let s:first_rtp = s:esc(get(split(&rtp, ','), 0, ''))

View File

@@ -21,15 +21,23 @@ make_dirs() {
for d in *; do
cat > $d/xxx.vim << EOF
" echom expand('<sfile>')
let g:xxx = get(g:, 'xxx', [])
call add(g:xxx, '${1:4}/$d')
let g:$2 = get(g:, '$2', [])
call add(g:$2, '${1:4}/$d')
EOF
done
cd - > /dev/null
}
make_dirs xxx/
make_dirs xxx/after
make_dirs xxx/ xxx
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
set rtp+=vader.vim

View File

@@ -75,7 +75,7 @@ Execute (Subsequent plug#begin() calls will reuse g:plug_home):
Execute (Test Plug command):
" Git repo with branch
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 'yes-t_co', g:plugs['seoul256.vim'].branch
@@ -84,7 +84,7 @@ Execute (Test Plug command):
" Git repo with tag
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 '1.5.2', g:plugs['goyo.vim'].branch
@@ -99,7 +99,7 @@ Execute (Test Plug command):
" vim-scripts/
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 4, len(g:plugs)
@@ -199,8 +199,8 @@ Execute (PlugStatus):
call PlugStatusSorted()
Expect:
Expected: https://git:@github.com/junegunn.choi/seoul256.vim.git
Invalid URI: https://git:@github.com/junegunn/seoul256.vim.git
Expected: https://git::@github.com/junegunn.choi/seoul256.vim.git
Invalid URI: https://git::@github.com/junegunn/seoul256.vim.git
PlugClean required.
- vim-emoji: OK
Finished. 1 error(s).
@@ -233,7 +233,7 @@ Execute (PlugStatus):
call PlugStatusSorted()
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
Not found. Try PlugInstall.
PlugClean required.
@@ -307,6 +307,13 @@ Execute (Rollback recent updates, PlugUpdate, then PlugDiff):
AssertEqual lnum, line('.')
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
normal q
@@ -317,6 +324,7 @@ Execute (Rollback recent updates, PlugUpdate, then PlugDiff):
" q should not close preview window if it's already open
pedit
PlugDiff
AssertExpect '^- ', 1
execute "normal ]]j\<cr>"
normal q
@@ -330,8 +338,8 @@ Execute (Plug window in a new tab):
set buftype=nofile
PlugUpdate
normal D
AssertEqual 'No updates.', getline(1)
q
AssertExpect '^- ', 1
normal q
AssertEqual 'new-tab', expand('%')
q
q
@@ -762,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
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):
silent! call system('rm -rf '.temp_plugged)
silent! call rename('fzf', 'fzf-staged')