Skip to content
This repository was archived by the owner on Mar 6, 2023. It is now read-only.

Commit be80cfb

Browse files
committed
Refactor s:job_start()
Add stdout/stderr event handler for debugging
1 parent 9a063ce commit be80cfb

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

autoload/gen_tags.vim

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,33 @@ function! gen_tags#echo(str) abort
123123
endif
124124
endfunction
125125

126+
function! s:job_stdout(job_id, data, ...) abort
127+
call gen_tags#echo(a:data)
128+
endfunction
129+
126130
function! s:job_start(cmd, ...) abort
127131
if has('nvim')
128-
if a:0 == 0
129-
let l:job_id = jobstart(a:cmd)
130-
else
131-
let l:job_id = jobstart(a:cmd, {'on_exit': a:1})
132+
let l:job = {
133+
\ 'on_stdout': function('s:job_stdout'),
134+
\ 'on_stderr': function('s:job_stdout'),
135+
\ }
136+
137+
if a:0 != 0
138+
let l:job.on_exit = a:1
132139
endif
140+
141+
let l:job_id = jobstart(a:cmd, l:job)
133142
elseif has('job')
134-
if a:0 == 0
135-
let l:job_id = job_start(a:cmd)
136-
else
137-
let l:job_id = job_start(a:cmd, {'close_cb': a:1})
143+
let l:job = {
144+
\ 'out_cb': function('s:job_stdout'),
145+
\ 'err_cb': function('s:job_stdout'),
146+
\ }
147+
148+
if a:0 != 0
149+
let l:job.exit_cb = a:1
138150
endif
151+
152+
let l:job_id = job_start(a:cmd, l:job)
139153
else
140154
if has('unix')
141155
let l:cmd = a:cmd . ' &'

0 commit comments

Comments
 (0)