3
3
" Maintainer: skywind3000 (at) gmail.com, 2016-2022
4
4
" Homepage: https://github.com/skywind3000/asyncrun.vim
5
5
"
6
- " Last Modified: 2022/02/20 00:05
6
+ " Last Modified: 2022/03/08 14:33
7
7
"
8
8
" Run shell command in background and output to quickfix:
9
9
" :AsyncRun[!] [options] {cmd} ...
@@ -133,8 +133,8 @@ let g:asyncrun_mode = get(g:, 'asyncrun_mode', 0)
133
133
" Use quickfix-ID to allow concurrent use of quickfix list and not
134
134
" interleave streamed output of a running command with output from
135
135
" other plugins
136
- if ! exists (' g:asyncrun_qf_id ' )
137
- let g: asyncrun_qf_id = has (' patch-8.0.1023' ) || has (' nvim-0.6.1' )
136
+ if ! exists (' g:asyncrun_qfid ' )
137
+ let g: asyncrun_qfid = has (' patch-8.0.1023' ) || has (' nvim-0.6.1' )
138
138
endif
139
139
140
140
" command hook
@@ -314,12 +314,15 @@ if has('nvim')
314
314
endif
315
315
endif
316
316
317
+ " check qfid
318
+ let s: has_qfid = has (' patch-8.0.1023' ) || has (' nvim-0.6.1' )
319
+
317
320
318
321
" ----------------------------------------------------------------------
319
322
" - build in background
320
323
" ----------------------------------------------------------------------
321
324
let s: async_nvim = has (' nvim' )? 1 : 0
322
- let s: async_info = { ' text' :" " , ' post' :' ' , ' postsave' :' ' }
325
+ let s: async_info = { ' text' :" " , ' post' :' ' , ' postsave' :' ' , ' qfid ' : -1 }
323
326
let s: async_output = {}
324
327
let s: async_head = 0
325
328
let s: async_tail = 0
@@ -346,6 +349,48 @@ if s:async_nvim == 0 && v:version >= 800
346
349
let s: async_congest = 0
347
350
endif
348
351
352
+ " append to quickfix
353
+ function ! s: AppendText (textlist, raw)
354
+ let qfid = s: async_info .qfid
355
+ if qfid < 0
356
+ if a: raw == 0
357
+ if and (g: asyncrun_skip , 1 ) == 0
358
+ caddexpr a: textlist
359
+ else
360
+ noautocmd caddexpr a: textlist
361
+ endif
362
+ else
363
+ let items = []
364
+ for text in a: textlist
365
+ let items += [{' text' : text}]
366
+ endfor
367
+ if and (g: asyncrun_skip , 1 ) == 0
368
+ call setqflist (items , ' a' )
369
+ else
370
+ noautocmd call setqflist (items , ' a' )
371
+ endif
372
+ unlet items
373
+ endif
374
+ else
375
+ let info = {' id' : qfid}
376
+ if a: raw == 0
377
+ let info.lines = a: textlist
378
+ else
379
+ let items = []
380
+ for text in a: textlist
381
+ let items += [{' text' : text}]
382
+ endfor
383
+ let info.items = items
384
+ endif
385
+ if and (g: asyncrun_skip , 1 ) == 0
386
+ call setqflist ([], ' a' , info)
387
+ else
388
+ noautocmd call setqflist ([], ' a' , info)
389
+ endif
390
+ unlet info
391
+ endif
392
+ endfunc
393
+
349
394
" quickfix window cursor check
350
395
function ! s: AsyncRun_Job_Cursor ()
351
396
if &buftype == ' quickfix'
@@ -402,7 +447,6 @@ function! s:AsyncRun_Job_Update(count, ...)
402
447
let l: iconv = (encoding != " " )? 1 : 0
403
448
let l: count = 0
404
449
let l: total = 0
405
- let l: empty = [{' text' :' ' }]
406
450
let l: check = s: AsyncRun_Job_CheckScroll ()
407
451
let l: efm1 = &g: efm
408
452
let l: efm2 = &l: efm
@@ -437,34 +481,9 @@ function! s:AsyncRun_Job_Update(count, ...)
437
481
let l: text = substitute (l: text , ' \r$' , ' ' , ' g' )
438
482
if once == 0
439
483
if l: text != ' '
440
- if l: raw == 0
441
- if exists (' s:qf_id' )
442
- let qflist = {' id' : s: qf_id , ' lines' : split (l: text , " \n " )}
443
- if and (g: asyncrun_skip , 1 ) == 0
444
- call setqflist ([], ' a' , qflist)
445
- else
446
- noautocmd call setqflist ([], ' a' , qflist)
447
- endif
448
- else
449
- if and (g: asyncrun_skip , 1 ) == 0
450
- caddexpr l: text
451
- else
452
- noautocmd caddexpr l: text
453
- endif
454
- endif
455
- else
456
- if exists (' s:qf_id' )
457
- call setqflist ([], ' a' , {' id' : s: qf_id , ' items' : [{' text' :l: text }]})
458
- else
459
- call setqflist ([{' text' :l: text }], ' a' )
460
- endif
461
- endif
484
+ call s: AppendText ([l: text ], l: raw )
462
485
elseif g: asyncrun_trim == 0
463
- if exists (' s:qf_id' )
464
- call setqflist ([], ' a' , {' id' : s: qf_id , ' items' : l: empty })
465
- else
466
- call setqflist (l: empty , ' a' )
467
- endif
486
+ call s: AppendText ([' ' ], l: raw )
468
487
endif
469
488
else
470
489
if l: text != ' '
@@ -482,20 +501,7 @@ function! s:AsyncRun_Job_Update(count, ...)
482
501
endif
483
502
endwhile
484
503
if once != 0
485
- if l: raw == 0
486
- if and (g: asyncrun_skip , 1 ) == 0
487
- caddexpr array
488
- else
489
- noautocmd caddexpr array
490
- endif
491
- else
492
- let items = []
493
- for text in array
494
- let items += [{' text' : text}]
495
- endfor
496
- call setqflist (items , ' a' )
497
- unlet items
498
- endif
504
+ call s: AppendText (array, l: raw )
499
505
unlet array
500
506
endif
501
507
if pathfix != 0
@@ -592,31 +598,20 @@ function! s:AsyncRun_Job_OnFinish()
592
598
call timer_stop (s: async_timer )
593
599
unlet s: async_timer
594
600
endif
595
- if exists (' s:qf_id' )
596
- unlet s: qf_id
597
- endif
598
601
call s: AsyncRun_Job_Update (-1 , s: async_info .once)
599
602
let l: current = localtime ()
600
603
let l: last = l: current - s: async_start
601
604
let l: check = s: AsyncRun_Job_CheckScroll ()
602
605
if s: async_code == 0
603
606
let l: text = " [Finished in " .l: last ." seconds]"
604
607
if ! s: async_info .strip
605
- if exists (' s:qf_id' )
606
- call setqflist ([], ' a' , {' id' : s: qf_id , ' items' : [{' text' :l: text }]})
607
- else
608
- call setqflist ([{' text' :l: text }], ' a' )
609
- endif
608
+ call s: AppendText ([l: text ], 1 )
610
609
endif
611
610
let g: asyncrun_status = " success"
612
611
else
613
612
let l: text = ' with code ' .s: async_code
614
613
let l: text = " [Finished in " .l: last ." seconds " .l: text ." ]"
615
- if exists (' s:qf_id' )
616
- call setqflist ([], ' a' , {' id' : s: qf_id , ' lines' : [l: text ]})
617
- else
618
- call setqflist ([{' text' :l: text }], ' a' )
619
- endif
614
+ call s: AppendText ([l: text ], 1 )
620
615
let g: asyncrun_status = " failure"
621
616
endif
622
617
let s: async_state = 0
@@ -793,6 +788,7 @@ function! s:AsyncRun_Job_Start(cmd)
793
788
let s: async_info .auto = s: async_info .autosave
794
789
let s: async_info .postsave = ' '
795
790
let s: async_info .autosave = ' '
791
+ let s: async_info .qfid = -1
796
792
let g: asyncrun_text = s: async_info .text
797
793
call s: AutoCmd (' Pre' )
798
794
if s: async_nvim == 0
@@ -877,15 +873,11 @@ function! s:AsyncRun_Job_Start(cmd)
877
873
call setqflist ([], ' ' , l: title )
878
874
endif
879
875
endif
880
- if g: asyncrun_qf_id == 1
881
- let s: qf_id = getqflist ({' id' :0 }).id
876
+ if g: asyncrun_qfid && s: has_qfid
877
+ let s: async_info .qfid = getqflist ({' id' :0 }).id
882
878
endif
883
879
if ! s: async_info .strip
884
- if exists (' s:qf_id' )
885
- call setqflist ([], ' a' , {' id' : s: qf_id , ' lines' : [l: arguments ]})
886
- else
887
- call setqflist ([{' text' :l: arguments }], ' a' )
888
- endif
880
+ call s: AppendText ([l: arguments ], 1 )
889
881
endif
890
882
let l: name = ' g:AsyncRun_Job_OnTimer'
891
883
let s: async_timer = timer_start (100 , l: name , {' repeat' :-1 })
@@ -2100,7 +2092,7 @@ endfunc
2100
2092
" asyncrun - version
2101
2093
" ----------------------------------------------------------------------
2102
2094
function ! asyncrun#version ()
2103
- return ' 2.9.10 '
2095
+ return ' 2.9.11 '
2104
2096
endfunc
2105
2097
2106
2098
0 commit comments