@@ -188,7 +188,11 @@ function! s:extract_opts(command) abort
188
188
else
189
189
let val = 1
190
190
endif
191
- let opts[opt ] = substitute (val, ' \\\(\s\)' , ' \1' , ' g' )
191
+ if opt == # ' dir' || opt == # ' directory'
192
+ let opts.directory = fnamemodify (expand (val), ' :p' )
193
+ else
194
+ let opts[opt ] = substitute (val, ' \\\(\s\)' , ' \1' , ' g' )
195
+ endif
192
196
let command = substitute (command , ' ^-\w\+\%(=\%(\\.\|\S\)*\)\=\s*' , ' ' , ' ' )
193
197
endwhile
194
198
return [command , opts]
@@ -261,16 +265,27 @@ function! dispatch#spawn(command, ...) abort
261
265
endif
262
266
let request.file = tempname ()
263
267
let s: files [request.file ] = request
264
- if s: dispatch (request)
265
- if get (request, ' manage' )
266
- if ! has_key (g: DISPATCH_STARTS , key )
267
- let g: DISPATCH_STARTS [key ] = []
268
+ let cd = exists (' *haslocaldir' ) && haslocaldir () ? ' lcd' : ' cd'
269
+ try
270
+ if request.directory !=# getcwd ()
271
+ let cwd = getcwd ()
272
+ execute cd fnameescape (request.directory )
273
+ endif
274
+ if s: dispatch (request)
275
+ if get (request, ' manage' )
276
+ if ! has_key (g: DISPATCH_STARTS , key )
277
+ let g: DISPATCH_STARTS [key ] = []
278
+ endif
279
+ call add (g: DISPATCH_STARTS [key ], request.handler.' @' .dispatch#pid (request))
268
280
endif
269
- call add (g: DISPATCH_STARTS [key ], request.handler.' @' .dispatch#pid (request))
281
+ else
282
+ execute ' !' . request.command
270
283
endif
271
- else
272
- execute ' !' . request.command
273
- endif
284
+ finally
285
+ if exists (' cwd' )
286
+ execute cd fnameescape (cwd)
287
+ endif
288
+ endtry
274
289
return request
275
290
endfunction
276
291
@@ -444,7 +459,6 @@ function! dispatch#compile_command(bang, args, count) abort
444
459
call extend (request, {
445
460
\ ' action' : ' make' ,
446
461
\ ' background' : a: bang ,
447
- \ ' file' : tempname (),
448
462
\ ' format' : ' %+I%.%#'
449
463
\ }, ' keep' )
450
464
@@ -483,21 +497,27 @@ function! dispatch#compile_command(bang, args, count) abort
483
497
silent ! wall
484
498
endif
485
499
cclose
500
+ let request.file = tempname ()
486
501
let &errorfile = request.file
487
502
488
503
let efm = &l: efm
489
504
let makeprg = &l: makeprg
490
505
let compiler = get (b: , ' current_compiler' , ' ' )
491
506
let modelines = &modelines
492
507
let after = ' '
508
+ let cd = exists (' *haslocaldir' ) && haslocaldir () ? ' lcd' : ' cd'
493
509
try
494
510
let &modelines = 0
495
511
call s: set_current_compiler (get (request, ' compiler' , ' ' ))
496
512
let &l: efm = request.format
497
513
let &l: makeprg = request.command
498
514
silent doautocmd QuickFixCmdPre dispatch- make
499
- let request.directory = getcwd ()
500
- let request.expanded = dispatch#expand (request.command )
515
+ let request.directory = get (request, ' directory' , getcwd ())
516
+ if request.directory !=# getcwd ()
517
+ let cwd = getcwd ()
518
+ execute cd fnameescape (request.directory )
519
+ endif
520
+ let request.expanded = get (request, ' expanded' , dispatch#expand (request.command ))
501
521
call extend (s: makes , [request])
502
522
let request.id = len (s: makes )
503
523
let s: files [request.file ] = request
@@ -514,6 +534,9 @@ function! dispatch#compile_command(bang, args, count) abort
514
534
let &l: efm = efm
515
535
let &l: makeprg = makeprg
516
536
call s: set_current_compiler (compiler )
537
+ if exists (' cwd' )
538
+ execute cd fnameescape (cwd)
539
+ endif
517
540
endtry
518
541
execute after
519
542
return ' '
0 commit comments