@@ -86,20 +86,44 @@ function! s:execute(cmd, lines, indent, start_lineno, cb, ex_cb) abort
8686 echohl None
8787 return
8888 endif
89- if exists (' s:job' ) && job_status (s: job ) != ' stop'
90- call job_stop (s: job )
91- endif
9289
93- let s: job = job_start (a: cmd , {
94- \ ' callback' : {_, m - > a: cb (m , a: indent , a: start_lineno )},
95- \ ' exit_cb' : {_, m - > a: ex_cb (m )},
96- \ ' in_mode' : ' nl' ,
97- \ })
90+ if has (' nvim' )
91+ if exists (' s:job' )
92+ call jobstop (s: job )
93+ endif
94+
95+ let s: job = jobstart (a: cmd , {
96+ \ ' on_stdout' : {_c, m , _e - > a: cb (m , a: indent , a: start_lineno )},
97+ \ ' on_stderr' : {_c, m , _e - > a: cb (m , a: indent , a: start_lineno )},
98+ \ ' on_exit' : {_c, m , _e - > a: ex_cb (m )},
99+ \ })
100+
101+ if exists (' *chansend' )
102+ " Neovim >0.3.0
103+ call chansend (s: job , a: lines )
104+ call chanclose (s: job , ' stdin' )
105+ else
106+ " Legacy API
107+ call jobsend (s: job , a: lines )
108+ call jobclose (s: job , ' stdin' )
109+ endif
98110
99- let channel = job_getchannel (s: job )
100- if ch_status (channel) == # ' open'
101- call ch_sendraw (channel, a: lines )
102- call ch_close_in (channel)
111+ else
112+ if exists (' s:job' ) && job_status (s: job ) != ' stop'
113+ call job_stop (s: job )
114+ endif
115+
116+ let s: job = job_start (a: cmd , {
117+ \ ' callback' : {_, m - > a: cb (m , a: indent , a: start_lineno )},
118+ \ ' exit_cb' : {_, m - > a: ex_cb (m )},
119+ \ ' in_mode' : ' nl' ,
120+ \ })
121+
122+ let channel = job_getchannel (s: job )
123+ if ch_status (channel) == # ' open'
124+ call ch_sendraw (channel, a: lines )
125+ call ch_close_in (channel)
126+ endif
103127 endif
104128endfunction
105129
0 commit comments