Skip to content

Commit 58a0577

Browse files
author
skywind3000
committed
2.8.9 new dispatch event routines
1 parent 61c0df6 commit 58a0577

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

plugin/asyncrun.vim

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
" Maintainer: skywind3000 (at) gmail.com, 2016-2021
44
" Homepage: http://www.vim.org/scripts/script.php?script_id=5431
55
"
6-
" Last Modified: 2021/12/15 04:45
6+
" Last Modified: 2021/12/15 05:24
77
"
88
" Run shell command in background and output to quickfix:
99
" :AsyncRun[!] [options] {cmd} ...
@@ -195,6 +195,9 @@ let g:asyncrun_script = get(g:, 'asyncrun_script', '')
195195
" strict to execute vim script
196196
let g:asyncrun_strict = get(g:, 'asyncrun_strict', 0)
197197

198+
" events
199+
let g:asyncrun_event = get(g:, 'asyncrun_event', {})
200+
198201
" terminal job name
199202
let g:asyncrun_name = ''
200203

@@ -1403,6 +1406,33 @@ function! s:start_in_terminal(opts)
14031406
endfunc
14041407

14051408

1409+
"----------------------------------------------------------------------
1410+
" invoke event
1411+
"----------------------------------------------------------------------
1412+
function! s:DispatchEvent(name, ...)
1413+
if has_key(g:asyncrun_event, a:name)
1414+
let l:F = g:asyncrun_event[a:name]
1415+
if type(l:F) == type('')
1416+
let test = l:F
1417+
unlet l:F
1418+
let l:F = function(test)
1419+
endif
1420+
if a:0 == 0
1421+
call l:F()
1422+
else
1423+
let args = []
1424+
for index in range(a:0)
1425+
let args += ['a:' . (index + 1)]
1426+
endfor
1427+
let text = join(args, ',')
1428+
let cmd = 'call l:F(' . text . ')'
1429+
exec cmd
1430+
endif
1431+
unlet l:F
1432+
endif
1433+
endfunc
1434+
1435+
14061436
"----------------------------------------------------------------------
14071437
" run command
14081438
"----------------------------------------------------------------------
@@ -1435,6 +1465,7 @@ function! s:run(opts)
14351465
let l:opts.raw = 1
14361466
elseif type(l:mode) == 0 && l:mode == 6
14371467
let pos = get(l:opts, 'pos', '')
1468+
call s:DispatchEvent('runner', pos)
14381469
if has_key(g:asyncrun_runner, pos)
14391470
let l:runner = pos
14401471
elseif pos == 'bang' || pos == 'vim'
@@ -1779,11 +1810,9 @@ function! asyncrun#run(bang, opts, args, ...)
17791810
let l:macros['VIM_FILEEXT'] = ''
17801811
endif
17811812

1782-
" fire AsyncRunInit autocmd
1783-
if get(s:, 'asyncrun_init', 0) == 0
1784-
call s:AutoCmd('Init')
1785-
let s:asyncrun_init = 1
1786-
endif
1813+
" call init scripts
1814+
call s:DispatchEvent('init')
1815+
call s:AutoCmd('Init')
17871816

17881817
" extract options
17891818
let [l:command, l:opts] = s:ExtractOpt(s:StringStrip(a:args))
@@ -1924,7 +1953,7 @@ endfunc
19241953
" asyncrun - version
19251954
"----------------------------------------------------------------------
19261955
function! asyncrun#version()
1927-
return '2.8.8'
1956+
return '2.8.9'
19281957
endfunc
19291958

19301959

0 commit comments

Comments
 (0)