upgrade plug

This commit is contained in:
Felix Van der Jeugt 2016-09-09 17:16:32 +02:00
parent 4a5e965072
commit 13f53ab826
1 changed files with 92 additions and 28 deletions

View File

@ -171,14 +171,22 @@ function! s:assoc(dict, key, val)
let a:dict[a:key] = add(get(a:dict, a:key, []), a:val) let a:dict[a:key] = add(get(a:dict, a:key, []), a:val)
endfunction endfunction
function! s:ask(message) function! s:ask(message, ...)
call inputsave() call inputsave()
echohl WarningMsg echohl WarningMsg
let proceed = input(a:message.' (y/N) ') =~? '^y' let answer = input(a:message.(a:0 ? ' (y/N/a) ' : ' (y/N) '))
echohl None echohl None
call inputrestore() call inputrestore()
echo "\r" echo "\r"
return proceed return (a:0 && answer =~? '^a') ? 2 : (answer =~? '^y') ? 1 : 0
endfunction
function! s:ask_no_interrupt(...)
try
return call('s:ask', a:000)
catch
return 0
endtry
endfunction endfunction
function! plug#end() function! plug#end()
@ -196,6 +204,9 @@ function! plug#end()
filetype off filetype off
for name in g:plugs_order for name in g:plugs_order
if !has_key(g:plugs, name)
continue
endif
let plug = g:plugs[name] let plug = g:plugs[name]
if get(s:loaded, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for') if get(s:loaded, name, 0) || !has_key(plug, 'on') && !has_key(plug, 'for')
let s:loaded[name] = 1 let s:loaded[name] = 1
@ -264,7 +275,7 @@ function! plug#end()
syntax enable syntax enable
end end
else else
call s:reload() call s:reload_plugins()
endif endif
endfunction endfunction
@ -272,9 +283,13 @@ function! s:loaded_names()
return filter(copy(g:plugs_order), 'get(s:loaded, v:val, 0)') return filter(copy(g:plugs_order), 'get(s:loaded, v:val, 0)')
endfunction endfunction
function! s:reload() function! s:load_plugin(spec)
call s:source(s:rtp(a:spec), 'plugin/**/*.vim', 'after/plugin/**/*.vim')
endfunction
function! s:reload_plugins()
for name in s:loaded_names() for name in s:loaded_names()
call s:source(s:rtp(g:plugs[name]), 'plugin/**/*.vim', 'after/plugin/**/*.vim') call s:load_plugin(g:plugs[name])
endfor endfor
endfunction endfunction
@ -602,6 +617,7 @@ function! s:syntax()
syn match plugRelDate /([^)]*)$/ contained syn match plugRelDate /([^)]*)$/ contained
syn match plugNotLoaded /(not loaded)$/ syn match plugNotLoaded /(not loaded)$/
syn match plugError /^x.*/ syn match plugError /^x.*/
syn region plugDeleted start=/^\~ .*/ end=/^\ze\S/
syn match plugH2 /^.*:\n-\+$/ syn match plugH2 /^.*:\n-\+$/
syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean syn keyword Function PlugInstall PlugStatus PlugUpdate PlugClean
hi def link plug1 Title hi def link plug1 Title
@ -621,6 +637,7 @@ function! s:syntax()
hi def link plugUpdate Type hi def link plugUpdate Type
hi def link plugError Error hi def link plugError Error
hi def link plugDeleted Ignore
hi def link plugRelDate Comment hi def link plugRelDate Comment
hi def link plugEdge PreProc hi def link plugEdge PreProc
hi def link plugSha Identifier hi def link plugSha Identifier
@ -698,6 +715,12 @@ function! s:prepare(...)
throw 'Invalid current working directory. Cannot proceed.' throw 'Invalid current working directory. Cannot proceed.'
endif endif
for evar in ['$GIT_DIR', '$GIT_WORK_TREE']
if exists(evar)
throw evar.' detected. Cannot proceed.'
endif
endfor
call s:job_abort() call s:job_abort()
if s:switch_in() if s:switch_in()
normal q normal q
@ -713,10 +736,9 @@ function! s:prepare(...)
let s:plug_buf = winbufnr(0) let s:plug_buf = winbufnr(0)
call s:assign_name() call s:assign_name()
silent! unmap <buffer> <cr> for k in ['<cr>', 'L', 'o', 'X', 'd', 'dd']
silent! unmap <buffer> L execute 'silent! unmap <buffer>' k
silent! unmap <buffer> o endfor
silent! unmap <buffer> X
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline modifiable setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap cursorline modifiable
setf vim-plug setf vim-plug
if exists('g:syntax_on') if exists('g:syntax_on')
@ -782,7 +804,12 @@ function! s:do(pull, force, todo)
let error = '' let error = ''
let type = type(spec.do) let type = type(spec.do)
if type == s:TYPE.string if type == s:TYPE.string
if spec.do[0] == ':'
call s:load_plugin(spec)
execute spec.do[1:]
else
let error = s:bang(spec.do) let error = s:bang(spec.do)
endif
elseif type == s:TYPE.funcref elseif type == s:TYPE.funcref
try try
let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged') let status = installed ? 'installed' : (updated ? 'updated' : 'unchanged')
@ -793,6 +820,7 @@ function! s:do(pull, force, todo)
else else
let error = 'Invalid hook type' let error = 'Invalid hook type'
endif endif
call s:switch_in()
call setline(4, empty(error) ? (getline(4) . 'OK') call setline(4, empty(error) ? (getline(4) . 'OK')
\ : ('x' . getline(4)[1:] . error)) \ : ('x' . getline(4)[1:] . error))
if !empty(error) if !empty(error)
@ -1016,18 +1044,18 @@ function! s:update_finish()
call s:log4(name, 'Updating submodules. This may take a while.') call s:log4(name, 'Updating submodules. This may take a while.')
let out .= s:bang('git submodule update --init --recursive 2>&1', spec.dir) let out .= s:bang('git submodule update --init --recursive 2>&1', spec.dir)
endif endif
let msg = printf('%s %s: %s', v:shell_error ? 'x': '-', name, s:lastline(out)) let msg = s:format_message(v:shell_error ? 'x': '-', name, out)
if v:shell_error if v:shell_error
call add(s:update.errors, name) call add(s:update.errors, name)
call s:regress_bar() call s:regress_bar()
execute pos 'd _' silent execute pos 'd _'
call append(4, msg) | 4 call append(4, msg) | 4
elseif !empty(out) elseif !empty(out)
call setline(pos, msg) call setline(pos, msg[0])
endif endif
redraw redraw
endfor endfor
4 d _ silent 4 d _
call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && has_key(v:val, "do")')) call s:do(s:update.pull, s:update.force, filter(copy(s:update.all), 'index(s:update.errors, v:key) < 0 && has_key(v:val, "do")'))
call s:finish(s:update.pull) call s:finish(s:update.pull)
call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.') call setline(1, 'Updated. Elapsed time: ' . split(reltimestr(reltime(s:update.start)))[0] . ' sec.')
@ -1144,7 +1172,7 @@ function! s:log(bullet, name, lines)
if s:switch_in() if s:switch_in()
let pos = s:logpos(a:name) let pos = s:logpos(a:name)
if pos > 0 if pos > 0
execute pos 'd _' silent execute pos 'd _'
if pos > winheight('.') if pos > winheight('.')
let pos = 4 let pos = 4
endif endif
@ -1970,16 +1998,48 @@ function! s:clean(force)
if empty(todo) if empty(todo)
call append(line('$'), 'Already clean.') call append(line('$'), 'Already clean.')
else else
if a:force || s:ask('Proceed?') let s:clean_count = 0
for dir in todo call append(3, ['Directories to delete:', ''])
call s:rm_rf(dir) redraw!
endfor if a:force || s:ask_no_interrupt('Delete all directories?')
call append(3, ['Removed.', '']) call s:delete([6, line('$')], 1)
else else
call append(3, ['Cancelled.', '']) call setline(4, 'Cancelled.')
nnoremap <silent> <buffer> d :set opfunc=<sid>delete_op<cr>g@
nmap <silent> <buffer> dd d_
xnoremap <silent> <buffer> d :<c-u>call <sid>delete_op(visualmode(), 1)<cr>
echo 'Delete the lines (d{motion}) to delete the corresponding directories'
endif endif
endif endif
4 4
setlocal nomodifiable
endfunction
function! s:delete_op(type, ...)
call s:delete(a:0 ? [line("'<"), line("'>")] : [line("'["), line("']")], 0)
endfunction
function! s:delete(range, force)
let [l1, l2] = a:range
let force = a:force
while l1 <= l2
let line = getline(l1)
if line =~ '^- ' && isdirectory(line[2:])
execute l1
redraw!
let answer = force ? 1 : s:ask('Delete '.line[2:].'?', 1)
let force = force || answer > 1
if answer
call s:rm_rf(line[2:])
setlocal modifiable
call setline(l1, '~'.line[1:])
let s:clean_count += 1
call setline(4, printf('Removed %d directories.', s:clean_count))
setlocal nomodifiable
endif
endif
let l1 += 1
endwhile
endfunction endfunction
function! s:upgrade() function! s:upgrade()
@ -2121,11 +2181,15 @@ function! s:preview_commit()
return return
endif endif
if exists('g:plug_pwindow') && !s:is_preview_window_open()
execute g:plug_pwindow
execute 'e' sha
else
execute 'pedit' sha execute 'pedit' sha
wincmd P wincmd P
setlocal filetype=git buftype=nofile nobuflisted modifiable endif
execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha setlocal previewwindow filetype=git buftype=nofile nobuflisted modifiable
normal! gg"_dd execute 'silent %!cd' s:shellesc(g:plugs[name].dir) '&& git show --no-color --pretty=medium' sha
setlocal nomodifiable setlocal nomodifiable
nnoremap <silent> <buffer> q :q<cr> nnoremap <silent> <buffer> q :q<cr>
wincmd p wincmd p
@ -2211,7 +2275,7 @@ function! s:revert()
setlocal modifiable setlocal modifiable
normal! "_dap normal! "_dap
setlocal nomodifiable setlocal nomodifiable
echo 'Reverted.' echo 'Reverted'
endfunction endfunction
function! s:snapshot(force, ...) abort function! s:snapshot(force, ...) abort