1
0

update vim-plug

This commit is contained in:
valeth 2015-06-16 23:10:07 +02:00
parent 037e21abed
commit b57eabd052

View File

@ -14,6 +14,9 @@
" Plug 'junegunn/seoul256.vim' " Plug 'junegunn/seoul256.vim'
" Plug 'junegunn/vim-easy-align' " Plug 'junegunn/vim-easy-align'
" "
" " Group dependencies, vim-snippets depends on ultisnips
" Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
"
" " On-demand loading " " On-demand loading
" Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" Plug 'tpope/vim-fireplace', { 'for': 'clojure' } " Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
@ -356,7 +359,9 @@ function! plug#load(...)
for name in a:000 for name in a:000
call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) call s:lod([name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin'])
endfor endfor
doautocmd BufRead if exists('#BufRead')
doautocmd BufRead
endif
return 1 return 1
endfunction endfunction
@ -386,14 +391,21 @@ function! s:lod(names, types)
for dir in a:types for dir in a:types
call s:source(rtp, dir.'/**/*.vim') call s:source(rtp, dir.'/**/*.vim')
endfor endfor
if exists('#User#'.name)
execute 'doautocmd User' name
endif
endfor endfor
endfunction endfunction
function! s:lod_ft(pat, names) function! s:lod_ft(pat, names)
call s:lod(a:names, ['plugin', 'after/plugin']) call s:lod(a:names, ['plugin', 'after/plugin'])
execute 'autocmd! PlugLOD FileType' a:pat execute 'autocmd! PlugLOD FileType' a:pat
doautocmd filetypeplugin FileType if exists('#filetypeplugin#FileType')
doautocmd filetypeindent FileType doautocmd filetypeplugin FileType
endif
if exists('#filetypeindent#FileType')
doautocmd filetypeindent FileType
endif
endfunction endfunction
function! s:lod_cmd(cmd, bang, l1, l2, args, names) function! s:lod_cmd(cmd, bang, l1, l2, args, names)
@ -428,7 +440,7 @@ function! s:add(repo, ...)
call add(g:plugs_order, name) call add(g:plugs_order, name)
endif endif
let g:plugs[name] = spec let g:plugs[name] = spec
let s:loaded[name] = 0 let s:loaded[name] = get(s:loaded, name, 0)
catch catch
return s:err(v:exception) return s:err(v:exception)
endtry endtry
@ -764,6 +776,7 @@ function! s:update_impl(pull, force, args) abort
call s:prepare() call s:prepare()
call append(0, ['', '']) call append(0, ['', ''])
normal! 2G normal! 2G
silent! redraw
let s:clone_opt = get(g:, 'plug_shallow', 1) ? let s:clone_opt = get(g:, 'plug_shallow', 1) ?
\ '--depth 1' . (s:git_version_requirement(1, 7, 10) ? ' --no-single-branch' : '') : '' \ '--depth 1' . (s:git_version_requirement(1, 7, 10) ? ' --no-single-branch' : '') : ''
@ -1051,27 +1064,6 @@ class InvalidURI(BaseExc):
class Action(object): class Action(object):
INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-'] INSTALL, UPDATE, ERROR, DONE = ['+', '*', 'x', '-']
class GLog(object):
ON = None
LOGDIR = None
@classmethod
def write(cls, msg):
if cls.ON is None:
cls.ON = int(vim.eval('get(g:, "plug_log_on", 0)'))
cls.LOGDIR = os.path.expanduser(vim.eval('get(g:, "plug_logs", "~/plug_logs")'))
if cls.ON:
if not os.path.exists(cls.LOGDIR):
os.makedirs(cls.LOGDIR)
cls._write(msg)
@classmethod
def _write(cls, msg):
name = thr.current_thread().name
fname = cls.LOGDIR + os.path.sep + name
with open(fname, 'ab') as flog:
ltime = datetime.datetime.now().strftime("%H:%M:%S.%f")
msg = '[{0},{1}] {2}{3}'.format(name, ltime, msg, '\n')
flog.write(msg.encode())
class Buffer(object): class Buffer(object):
def __init__(self, lock, num_plugs, is_pull, is_win): def __init__(self, lock, num_plugs, is_pull, is_win):
self.bar = '' self.bar = ''
@ -1132,7 +1124,7 @@ class Buffer(object):
self.header() self.header()
except vim.error: except vim.error:
GLog.write('Buffer Update FAILED.') pass
class Command(object): class Command(object):
def __init__(self, cmd, cmd_dir=None, timeout=60, ntries=3, cb=None, clean=None): def __init__(self, cmd, cmd_dir=None, timeout=60, ntries=3, cb=None, clean=None):
@ -1285,10 +1277,8 @@ class Plugin(object):
'git merge --ff-only {0}'.format(self.merge), 'git merge --ff-only {0}'.format(self.merge),
'git submodule update --init --recursive'] 'git submodule update --init --recursive']
cmd = ' 2>&1 && '.join(cmds) cmd = ' 2>&1 && '.join(cmds)
GLog.write(cmd)
com = Command(cmd, self.args['dir'], G_TIMEOUT, G_RETRIES, callback) com = Command(cmd, self.args['dir'], G_TIMEOUT, G_RETRIES, callback)
result = com.attempt_cmd() result = com.attempt_cmd()
GLog.write(result)
self.write(Action.DONE, self.name, result[-1:]) self.write(Action.DONE, self.name, result[-1:])
else: else:
self.write(Action.DONE, self.name, ['Already installed']) self.write(Action.DONE, self.name, ['Already installed'])
@ -1300,7 +1290,6 @@ class Plugin(object):
return result[-1] return result[-1]
def write(self, action, name, msg): def write(self, action, name, msg):
GLog.write('{0} {1}: {2}'.format(action, name, '\n'.join(msg)))
self.buf_q.put((action, name, msg)) self.buf_q.put((action, name, msg))
class PlugThread(thr.Thread): class PlugThread(thr.Thread):
@ -1316,12 +1305,11 @@ class PlugThread(thr.Thread):
try: try:
while not G_STOP.is_set(): while not G_STOP.is_set():
name, args = work_q.get_nowait() name, args = work_q.get_nowait()
GLog.write('{0}: Dir {1}'.format(name, args['dir']))
plug = Plugin(name, args, buf_q, lock) plug = Plugin(name, args, buf_q, lock)
plug.manage() plug.manage()
work_q.task_done() work_q.task_done()
except queue.Empty: except queue.Empty:
GLog.write('Queue now empty.') pass
finally: finally:
global G_THREADS global G_THREADS
with lock: with lock:
@ -1368,17 +1356,10 @@ def nonblock_read(fname):
def main(): def main():
thr.current_thread().name = 'main' thr.current_thread().name = 'main'
GLog.write('')
if GLog.ON and os.path.exists(GLog.LOGDIR):
shutil.rmtree(GLog.LOGDIR)
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' is_win = vim.eval('s:is_win') == '1'
GLog.write('Plugs: {0}'.format(plugs))
GLog.write('PULL: {0}, WIN: {1}, MAC: {2}'.format(G_PULL, is_win, mac_gui))
GLog.write('Num Threads: {0}'.format(nthreads))
lock = thr.Lock() lock = thr.Lock()
buf = Buffer(lock, len(plugs), G_PULL, is_win) buf = Buffer(lock, len(plugs), G_PULL, is_win)
@ -1386,7 +1367,6 @@ def main():
for work in plugs.items(): for work in plugs.items():
work_q.put(work) work_q.put(work)
GLog.write('Starting Threads')
global G_THREADS global G_THREADS
for num in range(nthreads): for num in range(nthreads):
tname = 'PlugT-{0:02}'.format(num) tname = 'PlugT-{0:02}'.format(num)
@ -1397,7 +1377,6 @@ def main():
rthread = RefreshThread(lock) rthread = RefreshThread(lock)
rthread.start() rthread.start()
GLog.write('Buffer Writing Loop')
while not buf_q.empty() or len(G_THREADS) != 0: while not buf_q.empty() or len(G_THREADS) != 0:
try: try:
action, name, msg = buf_q.get(True, 0.25) action, name, msg = buf_q.get(True, 0.25)
@ -1411,7 +1390,6 @@ def main():
if mac_gui: if mac_gui:
rthread.stop() rthread.stop()
rthread.join() rthread.join()
GLog.write('Cleanly Exited Main')
main() main()
EOF EOF
@ -1664,14 +1642,14 @@ endfunction
function! s:system(cmd, ...) function! s:system(cmd, ...)
try try
let sh = &shell let [sh, shrd] = [&shell, &shellredir]
if !s:is_win if !s:is_win
set shell=sh set shell=sh shellredir=>%s\ 2>&1
endif endif
let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd let cmd = a:0 > 0 ? s:with_cd(a:cmd, a:1) : a:cmd
return system(s:is_win ? '('.cmd.')' : cmd) return system(s:is_win ? '('.cmd.')' : cmd)
finally finally
let &shell = sh let [&shell, &shellredir] = [sh, shrd]
endtry endtry
endfunction endfunction
@ -1924,7 +1902,7 @@ function! s:preview_commit()
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 !cd' s:shellesc(g:plugs[name].dir) '&& git show' sha execute 'silent read !cd' s:shellesc(g:plugs[name].dir) '&& git show --pretty=medium' sha
normal! gg"_dd normal! gg"_dd
wincmd p wincmd p
endfunction endfunction