-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
windows.vim
50 lines (44 loc) · 1.58 KB
/
windows.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
" dispatch.vim Windows strategy
if exists('g:autoloaded_dispatch_windows')
finish
endif
let g:autoloaded_dispatch_windows = 1
function! s:escape(str)
if &shellxquote ==# '"'
return '"' . substitute(a:str, '"', '""', 'g') . '"'
else
let esc = exists('+shellxescape') ? &shellxescape : '"&|<>()@^'
return &shellquote .
\ substitute(a:str, '['.esc.']', '^&', 'g') .
\ get({'(': ')', '"(': ')"'}, &shellquote, &shellquote)
endif
endfunction
function! dispatch#windows#handle(request) abort
if !has('win32') || empty(v:servername)
return 0
endif
if a:request.action ==# 'make'
return dispatch#windows#make(a:request)
elseif a:request.action ==# 'start'
let title = get(a:request, 'title', matchstr(a:request.command, '\S\+'))
return dispatch#windows#spawn(title, a:request.command, a:request.background)
endif
endfunction
function! dispatch#windows#spawn(title, exec, background) abort
let extra = a:background ? ' /min' : ''
silent execute '!start /min cmd.exe /cstart ' .
\ '"' . substitute(a:title, '"', '', 'g') . '"' . extra . ' ' .
\ &shell . ' ' . &shellcmdflag . ' ' . s:escape(a:exec)
return 1
endfunction
function! dispatch#windows#make(request) abort
if &shellxquote ==# '"'
let exec = dispatch#prepare_make(a:request)
else
let exec = escape(a:request.expanded, '%#!') .
\ ' ' . dispatch#shellpipe(a:request.file) .
\ ' & cd . > ' . a:request.file . '.complete' .
\ ' & ' . dispatch#callback(a:request)
endif
return dispatch#windows#spawn(a:request.title, exec, 1)
endfunction