@@ -86,20 +86,44 @@ function! s:execute(cmd, lines, indent, start_lineno, cb, ex_cb) abort
86
86
echohl None
87
87
return
88
88
endif
89
- if exists (' s:job' ) && job_status (s: job ) != ' stop'
90
- call job_stop (s: job )
91
- endif
92
89
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
98
110
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
103
127
endif
104
128
endfunction
105
129
0 commit comments