|
3 | 3 | " Maintainer: skywind3000 (at) gmail.com, 2016-2021
|
4 | 4 | " Homepage: http://www.vim.org/scripts/script.php?script_id=5431
|
5 | 5 | "
|
6 |
| -" Last Modified: 2021/12/15 04:45 |
| 6 | +" Last Modified: 2021/12/15 05:24 |
7 | 7 | "
|
8 | 8 | " Run shell command in background and output to quickfix:
|
9 | 9 | " :AsyncRun[!] [options] {cmd} ...
|
@@ -195,6 +195,9 @@ let g:asyncrun_script = get(g:, 'asyncrun_script', '')
|
195 | 195 | " strict to execute vim script
|
196 | 196 | let g:asyncrun_strict = get(g:, 'asyncrun_strict', 0)
|
197 | 197 |
|
| 198 | +" events |
| 199 | +let g:asyncrun_event = get(g:, 'asyncrun_event', {}) |
| 200 | + |
198 | 201 | " terminal job name
|
199 | 202 | let g:asyncrun_name = ''
|
200 | 203 |
|
@@ -1403,6 +1406,33 @@ function! s:start_in_terminal(opts)
|
1403 | 1406 | endfunc
|
1404 | 1407 |
|
1405 | 1408 |
|
| 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 | + |
1406 | 1436 | "----------------------------------------------------------------------
|
1407 | 1437 | " run command
|
1408 | 1438 | "----------------------------------------------------------------------
|
@@ -1435,6 +1465,7 @@ function! s:run(opts)
|
1435 | 1465 | let l:opts.raw = 1
|
1436 | 1466 | elseif type(l:mode) == 0 && l:mode == 6
|
1437 | 1467 | let pos = get(l:opts, 'pos', '')
|
| 1468 | + call s:DispatchEvent('runner', pos) |
1438 | 1469 | if has_key(g:asyncrun_runner, pos)
|
1439 | 1470 | let l:runner = pos
|
1440 | 1471 | elseif pos == 'bang' || pos == 'vim'
|
@@ -1779,11 +1810,9 @@ function! asyncrun#run(bang, opts, args, ...)
|
1779 | 1810 | let l:macros['VIM_FILEEXT'] = ''
|
1780 | 1811 | endif
|
1781 | 1812 |
|
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') |
1787 | 1816 |
|
1788 | 1817 | " extract options
|
1789 | 1818 | let [l:command, l:opts] = s:ExtractOpt(s:StringStrip(a:args))
|
@@ -1924,7 +1953,7 @@ endfunc
|
1924 | 1953 | " asyncrun - version
|
1925 | 1954 | "----------------------------------------------------------------------
|
1926 | 1955 | function! asyncrun#version()
|
1927 |
| - return '2.8.8' |
| 1956 | + return '2.8.9' |
1928 | 1957 | endfunc
|
1929 | 1958 |
|
1930 | 1959 |
|
|
0 commit comments