-
-
Notifications
You must be signed in to change notification settings - Fork 138
Expand file tree
/
Copy pathscreen.vim
More file actions
74 lines (65 loc) · 1.99 KB
/
Copy pathscreen.vim
File metadata and controls
74 lines (65 loc) · 1.99 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
" dispatch.vim GNU Screen strategy
if exists('g:autoloaded_dispatch_screen')
finish
endif
let g:autoloaded_dispatch_screen = 1
let s:waiting = {}
function! dispatch#screen#handle(request) abort
if empty($STY) || !executable('screen')
return 0
endif
let aftercmd = 'screen -X only; screen -X at $WINDOW kill'
if a:request.action ==# 'make'
if !get(a:request, 'background', 0) && empty(v:servername) && !empty(s:waiting)
return 0
endif
let cmd = dispatch#prepare_make(a:request, aftercmd)
return dispatch#screen#spawn(cmd, a:request)
elseif a:request.action ==# 'start'
let cmd = dispatch#prepare_start(a:request, aftercmd)
return dispatch#screen#spawn(cmd, a:request)
endif
endfunction
function! dispatch#screen#spawn(command, request) abort
let command = ''
if !get(a:request, 'background', 0)
silent execute "!screen -X eval 'split' 'focus down' 'resize 10'"
endif
let command .= 'screen -ln -fn -t '.dispatch#shellescape(a:request.title)
\ . ' ' . &shell . ' ' . &shellcmdflag . ' '
\ . shellescape('exec ' . dispatch#isolate(['STY', 'WINDOW'],
\ dispatch#set_title(a:request), a:command))
silent execute '!' . escape(command, '!#%')
if a:request.background
silent !screen -X other
else
silent !screen -X focus up
endif
let s:waiting = a:request
return 1
endfunction
function! dispatch#screen#activate(pid) abort
let out = system('ps ewww -p '.a:pid)
if empty($STY) || stridx(out, 'STY='.$STY) < 0
return 0
endif
let window = matchstr(out, 'WINDOW=\zs\d\+')
if !empty(window)
silent execute '!screen -X select '.window
return !v:shell_error
endif
endfunction
function! dispatch#screen#poll() abort
if empty(s:waiting)
return
endif
let request = s:waiting
if !dispatch#pid(request)
let s:waiting = {}
call dispatch#complete(request)
endif
endfunction
augroup dispatch_screen
autocmd!
autocmd VimResized * if !has('gui_running') | call dispatch#screen#poll() | endif
augroup END