3
3
" Maintainer: skywind3000 (at) gmail.com, 2016-2021
4
4
" Homepage: https://github.com/skywind3000/asyncrun.vim
5
5
"
6
- " Last Modified: 2021/12/20 03:43
6
+ " Last Modified: 2021/12/20 04:44
7
7
"
8
8
" Run shell command in background and output to quickfix:
9
9
" :AsyncRun[!] [options] {cmd} ...
@@ -389,14 +389,15 @@ function! s:AsyncRun_Job_CheckScroll()
389
389
endfunc
390
390
391
391
" invoked on timer or finished
392
- function ! s: AsyncRun_Job_Update (count )
392
+ function ! s: AsyncRun_Job_Update (count , ... )
393
393
let l: iconv = (g: asyncrun_encs != " " )? 1 : 0
394
394
let l: count = 0
395
395
let l: total = 0
396
396
let l: empty = [{' text' :' ' }]
397
397
let l: check = s: AsyncRun_Job_CheckScroll ()
398
398
let l: efm1 = &g: efm
399
399
let l: efm2 = &l: efm
400
+ let once = (a: 0 < 1 )? get (g: , ' asyncrun_once' , 0 ) : (a: 1 )
400
401
if g: asyncrun_encs == &encoding
401
402
let l: iconv = 0
402
403
endif
@@ -408,6 +409,9 @@ function! s:AsyncRun_Job_Update(count)
408
409
if s: async_info .raw == 1
409
410
let l: raw = 1
410
411
endif
412
+ if once != 0
413
+ let array = []
414
+ endif
411
415
while s: async_tail < s: async_head
412
416
let l: text = s: async_output [s: async_tail ]
413
417
if l: iconv != 0
@@ -417,18 +421,26 @@ function! s:AsyncRun_Job_Update(count)
417
421
endtry
418
422
endif
419
423
let l: text = substitute (l: text , ' \r$' , ' ' , ' g' )
420
- if l: text != ' '
421
- if l: raw == 0
422
- if and (g: asyncrun_skip , 1 ) == 0
423
- caddexpr l: text
424
+ if once == 0
425
+ if l: text != ' '
426
+ if l: raw == 0
427
+ if and (g: asyncrun_skip , 1 ) == 0
428
+ caddexpr l: text
429
+ else
430
+ noautocmd caddexpr l: text
431
+ endif
424
432
else
425
- noautocmd caddexpr l: text
433
+ call setqflist ([{ ' text ' : l: text}], ' a ' )
426
434
endif
427
- else
428
- call setqflist ([{' text' :l: text }], ' a' )
435
+ elseif g: asyncrun_trim == 0
436
+ call setqflist (l: empty , ' a' )
437
+ endif
438
+ else
439
+ if l: text != ' '
440
+ let array += [l: text ]
441
+ elseif g: asyncrun_trim == 0
442
+ let array += [l: text ]
429
443
endif
430
- elseif g: asyncrun_trim == 0
431
- call setqflist (l: empty , ' a' )
432
444
endif
433
445
let l: total += 1
434
446
unlet s: async_output [s: async_tail ]
@@ -438,6 +450,23 @@ function! s:AsyncRun_Job_Update(count)
438
450
break
439
451
endif
440
452
endwhile
453
+ if once != 0
454
+ if l: raw == 0
455
+ if and (g: asyncrun_skip , 1 ) == 0
456
+ caddexpr array
457
+ else
458
+ noautocmd caddexpr array
459
+ endif
460
+ else
461
+ let items = []
462
+ for text in array
463
+ let items += [{' text' : text}]
464
+ endfor
465
+ call setqflist (items , ' a' )
466
+ unlet items
467
+ endif
468
+ unlet array
469
+ endif
441
470
if g: asyncrun_local != 0
442
471
if l: efm1 != &g: efm | let &g: efm = l: efm1 | endif
443
472
if l: efm2 != &l: efm | let &l: efm = l: efm2 | endif
@@ -485,8 +514,13 @@ function! g:AsyncRun_Job_OnTimer(id)
485
514
call job_status (s: async_job )
486
515
endif
487
516
endif
488
- call s: AsyncRun_Job_Update (limit)
517
+ if s: async_info .once == 0
518
+ call s: AsyncRun_Job_Update (limit)
519
+ endif
489
520
if and (s: async_state , 7 ) == 7
521
+ if s: async_info .once != 0
522
+ call s: AsyncRun_Job_Update (-1 , 1 )
523
+ endif
490
524
if s: async_head == s: async_tail
491
525
call s: AsyncRun_Job_OnFinish ()
492
526
endif
@@ -504,7 +538,9 @@ function! s:AsyncRun_Job_OnCallback(channel, text)
504
538
let s: async_output [s: async_head ] = a: text
505
539
let s: async_head += 1
506
540
if s: async_congest != 0
507
- call s: AsyncRun_Job_Update (-1 )
541
+ if s: async_info .once == 0
542
+ call s: AsyncRun_Job_Update (-1 )
543
+ endif
508
544
endif
509
545
endfunc
510
546
@@ -522,7 +558,7 @@ function! s:AsyncRun_Job_OnFinish()
522
558
call timer_stop (s: async_timer )
523
559
unlet s: async_timer
524
560
endif
525
- call s: AsyncRun_Job_Update (-1 )
561
+ call s: AsyncRun_Job_Update (-1 , s: async_info .once )
526
562
let l: current = localtime ()
527
563
let l: last = l: current - s: async_start
528
564
let l: check = s: AsyncRun_Job_CheckScroll ()
@@ -1658,6 +1694,7 @@ function! s:run(opts)
1658
1694
let s: async_info .range_buf = opts.range_buf
1659
1695
let s: async_info .strip = opts.strip
1660
1696
let s: async_info .append = opts.append
1697
+ let s: async_info .once = get (opts, ' once' , 0 )
1661
1698
if s: AsyncRun_Job_Start (l: command ) != 0
1662
1699
call s: AutoCmd (' Error' )
1663
1700
endif
@@ -2002,7 +2039,7 @@ endfunc
2002
2039
" asyncrun - version
2003
2040
" ----------------------------------------------------------------------
2004
2041
function ! asyncrun#version ()
2005
- return ' 2.9.4 '
2042
+ return ' 2.9.5 '
2006
2043
endfunc
2007
2044
2008
2045
0 commit comments