Skip to content

Commit

Permalink
2.8.9 new dispatch event routines
Browse files Browse the repository at this point in the history
  • Loading branch information
skywind3000 committed Dec 14, 2021
1 parent 61c0df6 commit 58a0577
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions plugin/asyncrun.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
" Maintainer: skywind3000 (at) gmail.com, 2016-2021
" Homepage: http://www.vim.org/scripts/script.php?script_id=5431
"
" Last Modified: 2021/12/15 04:45
" Last Modified: 2021/12/15 05:24
"
" Run shell command in background and output to quickfix:
" :AsyncRun[!] [options] {cmd} ...
Expand Down Expand Up @@ -195,6 +195,9 @@ let g:asyncrun_script = get(g:, 'asyncrun_script', '')
" strict to execute vim script
let g:asyncrun_strict = get(g:, 'asyncrun_strict', 0)

" events
let g:asyncrun_event = get(g:, 'asyncrun_event', {})

" terminal job name
let g:asyncrun_name = ''

Expand Down Expand Up @@ -1403,6 +1406,33 @@ function! s:start_in_terminal(opts)
endfunc


"----------------------------------------------------------------------
" invoke event
"----------------------------------------------------------------------
function! s:DispatchEvent(name, ...)
if has_key(g:asyncrun_event, a:name)
let l:F = g:asyncrun_event[a:name]
if type(l:F) == type('')
let test = l:F
unlet l:F
let l:F = function(test)
endif
if a:0 == 0
call l:F()
else
let args = []
for index in range(a:0)
let args += ['a:' . (index + 1)]
endfor
let text = join(args, ',')
let cmd = 'call l:F(' . text . ')'
exec cmd
endif
unlet l:F
endif
endfunc


"----------------------------------------------------------------------
" run command
"----------------------------------------------------------------------
Expand Down Expand Up @@ -1435,6 +1465,7 @@ function! s:run(opts)
let l:opts.raw = 1
elseif type(l:mode) == 0 && l:mode == 6
let pos = get(l:opts, 'pos', '')
call s:DispatchEvent('runner', pos)
if has_key(g:asyncrun_runner, pos)
let l:runner = pos
elseif pos == 'bang' || pos == 'vim'
Expand Down Expand Up @@ -1779,11 +1810,9 @@ function! asyncrun#run(bang, opts, args, ...)
let l:macros['VIM_FILEEXT'] = ''
endif

" fire AsyncRunInit autocmd
if get(s:, 'asyncrun_init', 0) == 0
call s:AutoCmd('Init')
let s:asyncrun_init = 1
endif
" call init scripts
call s:DispatchEvent('init')
call s:AutoCmd('Init')

" extract options
let [l:command, l:opts] = s:ExtractOpt(s:StringStrip(a:args))
Expand Down Expand Up @@ -1924,7 +1953,7 @@ endfunc
" asyncrun - version
"----------------------------------------------------------------------
function! asyncrun#version()
return '2.8.8'
return '2.8.9'
endfunc


Expand Down

0 comments on commit 58a0577

Please sign in to comment.