Merge pull request #79 from junegunn/U
Add `U` keybinding for updating plugins
This commit is contained in:
commit
a9fa8f44e5
3 changed files with 80 additions and 14 deletions
|
@ -97,6 +97,7 @@ Reload .vimrc and `:PlugInstall` to install plugins.
|
||||||
- `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`
|
- `:PlugStatus`
|
||||||
- `L` - Load plugin
|
- `L` - Load plugin
|
||||||
|
|
40
plug.vim
40
plug.vim
|
@ -107,8 +107,8 @@ function! s:define_commands()
|
||||||
if !executable('git')
|
if !executable('git')
|
||||||
return s:err('`git` executable not found. vim-plug requires git.')
|
return s:err('`git` executable not found. vim-plug requires git.')
|
||||||
endif
|
endif
|
||||||
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('<bang>' == '!', <f-args>)
|
command! -nargs=* -bar -bang -complete=customlist,s:names PlugInstall call s:install('<bang>' == '!', [<f-args>])
|
||||||
command! -nargs=* -bar -bang -complete=customlist,s:names PlugUpdate call s:update('<bang>' == '!', <f-args>)
|
command! -nargs=* -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 -bang PlugClean call s:clean('<bang>' == '!')
|
||||||
command! -nargs=0 -bar PlugUpgrade if s:upgrade() | execute 'source' s:me | endif
|
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 PlugStatus call s:status()
|
||||||
|
@ -387,12 +387,12 @@ function! s:infer_properties(name, repo)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:install(force, ...)
|
function! s:install(force, names)
|
||||||
call s:update_impl(0, a:force, a:000)
|
call s:update_impl(0, a:force, a:names)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:update(force, ...)
|
function! s:update(force, names)
|
||||||
call s:update_impl(1, a:force, a:000)
|
call s:update_impl(1, a:force, a:names)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! plug#helptags()
|
function! plug#helptags()
|
||||||
|
@ -476,10 +476,12 @@ function! s:prepare()
|
||||||
silent %d _
|
silent %d _
|
||||||
else
|
else
|
||||||
call s:new_window()
|
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
|
||||||
|
@ -624,9 +626,9 @@ function! s:update_impl(pull, force, 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)
|
||||||
|
@ -1120,17 +1122,20 @@ function! s:status()
|
||||||
normal! gg
|
normal! gg
|
||||||
setlocal nomodifiable
|
setlocal nomodifiable
|
||||||
if unloaded
|
if unloaded
|
||||||
echo "Press 'L' on each line to load plugin"
|
echo "Press 'L' on each line to load plugin, or 'U' to update"
|
||||||
nnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
|
nnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
|
||||||
xnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
|
xnoremap <silent> <buffer> L :call <SID>status_load(line('.'))<cr>
|
||||||
end
|
end
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:extract_name(str, prefix, suffix)
|
||||||
|
return matchstr(a:str, '^'.a:prefix.' \zs[^:]\+\ze:.*'.a:suffix.'$')
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! s:status_load(lnum)
|
function! s:status_load(lnum)
|
||||||
let line = getline(a:lnum)
|
let line = getline(a:lnum)
|
||||||
let matches = matchlist(line, '^- \([^:]*\):.*(not loaded)$')
|
let name = s:extract_name(line, '-', '(not loaded)')
|
||||||
if !empty(matches)
|
if !empty(name)
|
||||||
let name = matches[1]
|
|
||||||
call plug#load(name)
|
call plug#load(name)
|
||||||
setlocal modifiable
|
setlocal modifiable
|
||||||
call setline(a:lnum, substitute(line, ' (not loaded)$', '', ''))
|
call setline(a:lnum, substitute(line, ' (not loaded)$', '', ''))
|
||||||
|
@ -1138,6 +1143,15 @@ function! s:status_load(lnum)
|
||||||
endif
|
endif
|
||||||
endfunction
|
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
|
||||||
|
|
||||||
function! s:is_preview_window_open()
|
function! s:is_preview_window_open()
|
||||||
silent! wincmd P
|
silent! wincmd P
|
||||||
if &previewwindow
|
if &previewwindow
|
||||||
|
|
|
@ -27,7 +27,7 @@ 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>)
|
||||||
|
@ -873,6 +873,7 @@ Execute (Open plug window in a new tab):
|
||||||
normal S
|
normal S
|
||||||
AssertEqual tabnr, tabpagenr()
|
AssertEqual tabnr, tabpagenr()
|
||||||
q
|
q
|
||||||
|
unlet g:plug_window
|
||||||
|
|
||||||
**********************************************************************
|
**********************************************************************
|
||||||
~ g:plug_url_format
|
~ g:plug_url_format
|
||||||
|
@ -885,6 +886,56 @@ Execute (Using g:plug_url_format):
|
||||||
Plug 'beauty256'
|
Plug 'beauty256'
|
||||||
AssertEqual 'git@bitbucket.org:junegunn/seoul256.vim.git', g:plugs['seoul256.vim'].uri
|
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
|
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 (Cleanup):
|
Execute (Cleanup):
|
||||||
silent! call system('rm -rf '.temp_plugged)
|
silent! call system('rm -rf '.temp_plugged)
|
||||||
|
|
Loading…
Reference in a new issue