Skip to content

Commit 09cf638

Browse files
committed
Update Plug
1 parent 0dcd0d7 commit 09cf638

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

autoload/plug.vim

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -783,10 +783,11 @@ endfunction
783783
function! s:syntax()
784784
syntax clear
785785
syntax region plug1 start=/\%1l/ end=/\%2l/ contains=plugNumber
786-
syntax region plug2 start=/\%2l/ end=/\%3l/ contains=plugBracket,plugX
786+
syntax region plug2 start=/\%2l/ end=/\%3l/ contains=plugBracket,plugX,plugAbort
787787
syn match plugNumber /[0-9]\+[0-9.]*/ contained
788788
syn match plugBracket /[[\]]/ contained
789789
syn match plugX /x/ contained
790+
syn match plugAbort /\~/ contained
790791
syn match plugDash /^-\{1}\ /
791792
syn match plugPlus /^+/
792793
syn match plugStar /^*/
@@ -811,6 +812,7 @@ function! s:syntax()
811812
hi def link plug2 Repeat
812813
hi def link plugH2 Type
813814
hi def link plugX Exception
815+
hi def link plugAbort Ignore
814816
hi def link plugBracket Structure
815817
hi def link plugNumber Number
816818

@@ -908,7 +910,7 @@ function! s:prepare(...)
908910
endif
909911
endfor
910912

911-
call s:job_abort()
913+
call s:job_abort(0)
912914
if s:switch_in()
913915
if b:plug_preview == 1
914916
pc
@@ -944,6 +946,8 @@ function! s:close_pane()
944946
if b:plug_preview == 1
945947
pc
946948
let b:plug_preview = -1
949+
elseif exists('s:jobs') && !empty(s:jobs)
950+
call s:job_abort(1)
947951
else
948952
bd
949953
endif
@@ -1326,7 +1330,12 @@ function! s:update_finish()
13261330
endif
13271331
endfunction
13281332

1329-
function! s:job_abort()
1333+
function! s:mark_aborted(name, message)
1334+
let attrs = { 'running': 0, 'error': 1, 'abort': 1, 'lines': [a:message] }
1335+
let s:jobs[a:name] = extend(get(s:jobs, a:name, {}), attrs)
1336+
endfunction
1337+
1338+
function! s:job_abort(cancel)
13301339
if (!s:nvim && !s:vim8) || !exists('s:jobs')
13311340
return
13321341
endif
@@ -1340,8 +1349,18 @@ function! s:job_abort()
13401349
if j.new
13411350
call s:rm_rf(g:plugs[name].dir)
13421351
endif
1352+
if a:cancel
1353+
call s:mark_aborted(name, 'Aborted')
1354+
endif
13431355
endfor
1344-
let s:jobs = {}
1356+
1357+
if a:cancel
1358+
for todo in values(s:update.todo)
1359+
let todo.abort = 1
1360+
endfor
1361+
else
1362+
let s:jobs = {}
1363+
endif
13451364
endfunction
13461365

13471366
function! s:last_non_empty_line(lines)
@@ -1355,6 +1374,16 @@ function! s:last_non_empty_line(lines)
13551374
return ''
13561375
endfunction
13571376

1377+
function! s:bullet_for(job, ...)
1378+
if a:job.running
1379+
return a:job.new ? '+' : '*'
1380+
endif
1381+
if get(a:job, 'abort', 0)
1382+
return '~'
1383+
endif
1384+
return a:job.error ? 'x' : get(a:000, 0, '-')
1385+
endfunction
1386+
13581387
function! s:job_out_cb(self, data) abort
13591388
let self = a:self
13601389
let data = remove(self.lines, -1) . a:data
@@ -1363,10 +1392,9 @@ function! s:job_out_cb(self, data) abort
13631392
" To reduce the number of buffer updates
13641393
let self.tick = get(self, 'tick', -1) + 1
13651394
if !self.running || self.tick % len(s:jobs) == 0
1366-
let bullet = self.running ? (self.new ? '+' : '*') : (self.error ? 'x' : '-')
13671395
let result = self.error ? join(self.lines, "\n") : s:last_non_empty_line(self.lines)
13681396
if len(result)
1369-
call s:log(bullet, self.name, result)
1397+
call s:log(s:bullet_for(self), self.name, result)
13701398
endif
13711399
endif
13721400
endfunction
@@ -1380,7 +1408,7 @@ endfunction
13801408

13811409
function! s:job_cb(fn, job, ch, data)
13821410
if !s:plug_window_exists() " plug window closed
1383-
return s:job_abort()
1411+
return s:job_abort(0)
13841412
endif
13851413
call call(a:fn, [a:job, a:data])
13861414
endfunction
@@ -1452,17 +1480,16 @@ function! s:reap(name)
14521480
endif
14531481

14541482
let more = len(get(job, 'queue', []))
1455-
let bullet = job.error ? 'x' : more ? (job.new ? '+' : '*') : '-'
14561483
let result = job.error ? join(job.lines, "\n") : s:last_non_empty_line(job.lines)
14571484
if len(result)
1458-
call s:log(bullet, a:name, result)
1485+
call s:log(s:bullet_for(job), a:name, result)
14591486
endif
14601487

14611488
if !job.error && more
14621489
let job.spec.queue = job.queue
14631490
let s:update.todo[a:name] = job.spec
14641491
else
1465-
let s:update.bar .= job.error ? 'x' : '='
1492+
let s:update.bar .= s:bullet_for(job, '=')
14661493
call s:bar()
14671494
endif
14681495
endfunction
@@ -1541,6 +1568,12 @@ while 1 " Without TCO, Vim stack is bound to explode
15411568

15421569
let name = keys(s:update.todo)[0]
15431570
let spec = remove(s:update.todo, name)
1571+
if get(spec, 'abort', 0)
1572+
call s:mark_aborted(name, 'Skipped')
1573+
call s:reap(name)
1574+
continue
1575+
endif
1576+
15441577
let queue = get(spec, 'queue', [])
15451578
let new = empty(globpath(spec.dir, '.git', 1))
15461579

@@ -2281,7 +2314,10 @@ endfunction
22812314

22822315
function! s:with_cd(cmd, dir, ...)
22832316
let script = a:0 > 0 ? a:1 : 1
2284-
return printf('cd%s %s && %s', s:is_win ? ' /d' : '', plug#shellescape(a:dir, {'script': script}), a:cmd)
2317+
let pwsh = s:is_powershell(&shell)
2318+
let cd = s:is_win && !pwsh ? 'cd /d' : 'cd'
2319+
let sep = pwsh ? ';' : '&&'
2320+
return printf('%s %s %s %s', cd, plug#shellescape(a:dir, {'script': script, 'shell': &shell}), sep, a:cmd)
22852321
endfunction
22862322

22872323
function! s:system(cmd, ...)

0 commit comments

Comments
 (0)