1
0

update vim-plug

This commit is contained in:
valeth 2015-12-10 19:36:30 +01:00
parent e39d030d39
commit 62517b0684

View File

@ -761,7 +761,7 @@ endfunction
function! s:update_impl(pull, force, args) abort function! s:update_impl(pull, force, args) abort
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]*$') ?
\ remove(args, -1) : get(g:, 'plug_threads', s:is_win ? 1 : 16) \ remove(args, -1) : get(g:, 'plug_threads', 16)
let managed = filter(copy(g:plugs), 's:is_managed(v:key)') let managed = filter(copy(g:plugs), 's:is_managed(v:key)')
let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') : let todo = empty(args) ? filter(managed, '!v:val.frozen || !isdirectory(v:val.dir)') :
@ -798,9 +798,8 @@ function! s:update_impl(pull, force, args) abort
echohl None echohl None
endif endif
let python = (has('python') || has('python3')) && !s:is_win && !has('win32unix') let python = (has('python') || has('python3')) && (!s:nvim || has('vim_starting'))
\ && (!s:nvim || has('vim_starting')) let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374')) && !(s:is_win && has('gui_running'))
let ruby = has('ruby') && !s:nvim && (v:version >= 703 || v:version == 702 && has('patch374'))
let s:update = { let s:update = {
\ 'start': reltime(), \ 'start': reltime(),
@ -903,7 +902,13 @@ function! s:job_handler(job_id, data, event) abort
endif endif
if a:event == 'stdout' if a:event == 'stdout'
let self.result .= substitute(s:to_s(a:data), '[\r\n]', '', 'g') . "\n" let complete = empty(a:data[-1])
let lines = map(filter(a:data, 'len(v:val) > 0'), 'split(v:val, "[\r\n]")[-1]')
call extend(self.lines, lines)
let self.result = join(self.lines, "\n")
if !complete
call remove(self.lines, -1)
endif
" To reduce the number of buffer updates " To reduce the number of buffer updates
let self.tick = get(self, 'tick', -1) + 1 let self.tick = get(self, 'tick', -1) + 1
if self.tick % len(s:jobs) == 0 if self.tick % len(s:jobs) == 0
@ -920,7 +925,7 @@ function! s:job_handler(job_id, data, event) abort
endfunction endfunction
function! s:spawn(name, cmd, opts) function! s:spawn(name, cmd, opts)
let job = { 'name': a:name, 'running': 1, 'error': 0, 'result': '', let job = { 'name': a:name, 'running': 1, 'error': 0, 'lines': [], 'result': '',
\ 'new': get(a:opts, 'new', 0), \ 'new': get(a:opts, 'new', 0),
\ 'on_stdout': function('s:job_handler'), \ 'on_stdout': function('s:job_handler'),
\ 'on_exit' : function('s:job_handler'), \ 'on_exit' : function('s:job_handler'),
@ -1063,7 +1068,6 @@ endfunction
function! s:update_python() function! s:update_python()
let py_exe = has('python') ? 'python' : 'python3' let py_exe = has('python') ? 'python' : 'python3'
execute py_exe "<< EOF" execute py_exe "<< EOF"
""" Due to use of signals this function is POSIX only. """
import datetime import datetime
import functools import functools
import os import os
@ -1090,9 +1094,11 @@ G_CLONE_OPT = vim.eval('s:clone_opt')
G_PROGRESS = vim.eval('s:progress_opt(1)') G_PROGRESS = vim.eval('s:progress_opt(1)')
G_LOG_PROB = 1.0 / int(vim.eval('s:update.threads')) G_LOG_PROB = 1.0 / int(vim.eval('s:update.threads'))
G_STOP = thr.Event() G_STOP = thr.Event()
G_IS_WIN = vim.eval('s:is_win') == '1'
class PlugError(Exception): class PlugError(Exception):
pass def __init__(self, msg):
self.msg = msg
class CmdTimedOut(PlugError): class CmdTimedOut(PlugError):
pass pass
class CmdFailed(PlugError): class CmdFailed(PlugError):
@ -1103,10 +1109,9 @@ class Action(object):
INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-'] INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-']
class Buffer(object): class Buffer(object):
def __init__(self, lock, num_plugs, is_pull, is_win): def __init__(self, lock, num_plugs, is_pull):
self.bar = '' self.bar = ''
self.event = 'Updating' if is_pull else 'Installing' self.event = 'Updating' if is_pull else 'Installing'
self.is_win = is_win
self.lock = lock self.lock = lock
self.maxy = int(vim.eval('winheight(".")')) self.maxy = int(vim.eval('winheight(".")'))
self.num_plugs = num_plugs self.num_plugs = num_plugs
@ -1134,7 +1139,6 @@ class Buffer(object):
with self.lock: with self.lock:
vim.command('normal! 2G') vim.command('normal! 2G')
if not self.is_win:
vim.command('redraw') vim.command('redraw')
def write(self, action, name, lines): def write(self, action, name, lines):
@ -1166,7 +1170,8 @@ class Buffer(object):
class Command(object): class Command(object):
def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None): def __init__(self, cmd, cmd_dir=None, timeout=60, cb=None, clean=None):
self.cmd = cmd self.cmd = cmd
self.cmd_dir = cmd_dir if cmd_dir:
self.cmd = 'cd {0} && {1}'.format(cmd_dir, self.cmd)
self.timeout = timeout self.timeout = timeout
self.callback = cb if cb else (lambda msg: None) self.callback = cb if cb else (lambda msg: None)
self.clean = clean if clean else (lambda: None) self.clean = clean if clean else (lambda: None)
@ -1216,9 +1221,11 @@ class Command(object):
try: try:
tfile = tempfile.NamedTemporaryFile(mode='w+b') tfile = tempfile.NamedTemporaryFile(mode='w+b')
self.proc = subprocess.Popen(self.cmd, cwd=self.cmd_dir, stdout=tfile, preexec_fn = not G_IS_WIN and os.setsid or None
stderr=subprocess.STDOUT, shell=True, self.proc = subprocess.Popen(self.cmd, stdout=tfile,
preexec_fn=os.setsid) stderr=subprocess.STDOUT,
stdin=subprocess.PIPE, shell=True,
preexec_fn=preexec_fn)
thrd = thr.Thread(target=(lambda proc: proc.wait()), args=(self.proc,)) thrd = thr.Thread(target=(lambda proc: proc.wait()), args=(self.proc,))
thrd.start() thrd.start()
@ -1236,7 +1243,7 @@ class Command(object):
if first_line or random.random() < G_LOG_PROB: if first_line or random.random() < G_LOG_PROB:
first_line = False first_line = False
line = nonblock_read(tfile.name) line = '' if G_IS_WIN else nonblock_read(tfile.name)
if line: if line:
self.callback([line]) self.callback([line])
@ -1260,6 +1267,9 @@ class Command(object):
def terminate(self): def terminate(self):
""" Terminate process and cleanup. """ """ Terminate process and cleanup. """
if self.alive: if self.alive:
if G_IS_WIN:
os.kill(self.proc.pid, signal.SIGINT)
else:
os.killpg(self.proc.pid, signal.SIGTERM) os.killpg(self.proc.pid, signal.SIGTERM)
self.clean() self.clean()
@ -1283,7 +1293,7 @@ class Plugin(object):
with self.lock: with self.lock:
thread_vim_command("let s:update.new['{0}'] = 1".format(self.name)) thread_vim_command("let s:update.new['{0}'] = 1".format(self.name))
except PlugError as exc: except PlugError as exc:
self.write(Action.ERROR, self.name, [str(exc)]) self.write(Action.ERROR, self.name, exc.msg)
except KeyboardInterrupt: except KeyboardInterrupt:
G_STOP.set() G_STOP.set()
self.write(Action.ERROR, self.name, ['Interrupted!']) self.write(Action.ERROR, self.name, ['Interrupted!'])
@ -1411,10 +1421,9 @@ def main():
nthreads = int(vim.eval('s:update.threads')) nthreads = int(vim.eval('s:update.threads'))
plugs = vim.eval('s:update.todo') plugs = vim.eval('s:update.todo')
mac_gui = vim.eval('s:mac_gui') == '1' mac_gui = vim.eval('s:mac_gui') == '1'
is_win = vim.eval('s:is_win') == '1'
lock = thr.Lock() lock = thr.Lock()
buf = Buffer(lock, len(plugs), G_PULL, is_win) buf = Buffer(lock, len(plugs), G_PULL)
buf_q, work_q = queue.Queue(), queue.Queue() buf_q, work_q = queue.Queue(), queue.Queue()
for work in plugs.items(): for work in plugs.items():
work_q.put(work) work_q.put(work)
@ -1471,6 +1480,9 @@ function! s:update_ruby()
def killall pid def killall pid
pids = [pid] pids = [pid]
if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
pids.each { |pid| Process.kill 'INT', pid.to_i rescue nil }
else
unless `which pgrep 2> /dev/null`.empty? unless `which pgrep 2> /dev/null`.empty?
children = pids children = pids
until children.empty? until children.empty?
@ -1482,6 +1494,7 @@ function! s:update_ruby()
end end
pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil } pids.each { |pid| Process.kill 'TERM', pid.to_i rescue nil }
end end
end
require 'thread' require 'thread'
require 'fileutils' require 'fileutils'
@ -1506,7 +1519,7 @@ function! s:update_ruby()
$curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})" $curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
$curbuf[2] = '[' + bar.ljust(tot) + ']' $curbuf[2] = '[' + bar.ljust(tot) + ']'
VIM::command('normal! 2G') VIM::command('normal! 2G')
VIM::command('redraw') unless iswin VIM::command('redraw')
} }
where = proc { |name| (1..($curbuf.length)).find { |l| $curbuf[l] =~ /^[-+x*] #{name}:/ } } where = proc { |name| (1..($curbuf.length)).find { |l| $curbuf[l] =~ /^[-+x*] #{name}:/ } }
log = proc { |name, result, type| log = proc { |name, result, type|