Skip to content

Commit 0c56e38

Browse files
committed
Use job support plus FIFO for completion callback
1 parent 3312774 commit 0c56e38

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

autoload/dispatch.vim

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,17 +172,42 @@ function! dispatch#vim_executable() abort
172172
return s:vim
173173
endfunction
174174

175-
function! dispatch#has_callback() abort
176-
return has('clientserver') && !empty(v:servername)
175+
function dispatch#has_callback() abort
176+
if has('clientserver') && !empty(v:servername)
177+
return 1
178+
elseif !exists('*job_start') && !exists('*jobstart')
179+
return 0
180+
endif
181+
if !exists('s:has_temp_fifo')
182+
let fifo = tempname()
183+
call system('mkfifo ' . dispatch#shellescape(fifo))
184+
let s:has_temp_fifo = (getftype(fifo) ==# 'fifo')
185+
call delete(fifo)
186+
endif
187+
return s:has_temp_fifo
177188
endfunction
178189

179190
function! dispatch#callback(request) abort
180-
if has('clientserver') && !empty(v:servername) && has_key(s:request(a:request), 'id')
191+
let request = s:request(a:request)
192+
if !has_key(request, 'id') || !dispatch#has_callback()
193+
return ''
194+
endif
195+
if has('clientserver') && !empty(v:servername)
181196
return dispatch#shellescape(dispatch#vim_executable()) .
182197
\ ' --servername ' . dispatch#shellescape(v:servername) .
183-
\ ' --remote-expr "' . 'DispatchComplete(' . s:request(a:request).id . ')' . '"'
198+
\ ' --remote-expr "' . 'DispatchComplete(' . request.id . ')' . '"'
184199
endif
185-
return ''
200+
call system('mkfifo ' . dispatch#shellescape(request.file . '.callback'))
201+
let cmd = ['head', '-1', request.file . '.callback']
202+
let Cb = { ... -> dispatch#complete(request.id) }
203+
if exists('*job_start')
204+
call job_start(cmd, {'exit_cb': Cb})
205+
elseif exists('*jobstart')
206+
call jobstart(cmd, {'on_exit': Cb})
207+
else
208+
return ''
209+
endif
210+
return 'echo > ' . request.file . '.callback'
186211
endfunction
187212

188213
function! dispatch#autowrite() abort

doc/dispatch.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,15 @@ STRATEGIES *dispatch-strategies*
155155
Strategies are listed in order of precedence. The first available one is
156156
used. Some strategies only provide for a subset of tasks.
157157

158+
Except for Tmux, which uses |VimResized|, all strategies require either |job|
159+
support plus a file system with FIFOs (basically everything but Windows) or
160+
|clientserver| support to do foreground makes.
161+
158162
Tmux ~
159163

160164
Foreground makes open in a small split at the bottom. The closure of the
161165
pane triggers a |VimResized| event which loads the results into the quickfix
162-
list. (All other strategies use the GUI subsystem to get this to work.)
166+
list.
163167

164168
The tmux strategy can be used from the GUI as well. Either start Vim from
165169
inside of tmux or assign g:tmux_session. This will use a new window for
@@ -169,7 +173,7 @@ Tmux 1.6 or newer is required.
169173

170174
GNU Screen ~
171175

172-
Not used for foreground |:Make| invocations unless you're in GUI Vim.
176+
A new window is always used, since splits in GNU Screen are awkward.
173177

174178
Windows ~
175179

@@ -180,8 +184,7 @@ stealing.
180184
iTerm ~
181185

182186
This strategy fires if you're in MacVim with at least one iTerm window open,
183-
or if Vim is running in iTerm itself. In the latter case, you can't use it
184-
for foreground |:Make| invocations.
187+
or if Vim is running in iTerm itself.
185188

186189
X11 ~
187190

0 commit comments

Comments
 (0)