From 0fc19e90f2b80f1343df9072d7d4eedfed0cdd85 Mon Sep 17 00:00:00 2001 From: Rodrigo Moyle Date: Mon, 11 Aug 2014 16:07:28 -0300 Subject: [PATCH 1/4] Added support to screen foreground, fixes #83. --- autoload/dispatch/screen.vim | 42 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/autoload/dispatch/screen.vim b/autoload/dispatch/screen.vim index 2e9702b3..422ffd35 100644 --- a/autoload/dispatch/screen.vim +++ b/autoload/dispatch/screen.vim @@ -5,14 +5,13 @@ if exists('g:autoloaded_dispatch_screen') endif let g:autoloaded_dispatch_screen = 1 +let s:waiting = {} + function! dispatch#screen#handle(request) abort if empty($STY) || !executable('screen') return 0 endif if a:request.action ==# 'make' - if !get(a:request, 'background', 0) && empty(v:servername) - return 0 - endif return dispatch#screen#spawn(dispatch#prepare_make(a:request), a:request) elseif a:request.action ==# 'start' return dispatch#screen#spawn(dispatch#prepare_start(a:request), a:request) @@ -20,14 +19,27 @@ function! dispatch#screen#handle(request) abort endfunction function! dispatch#screen#spawn(command, request) abort + let teardown = 'screen -X eval "focus bottom" "remove"' + if a:request.background + let teardown = '' + 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, '!#%') + \ dispatch#set_title(a:request), a:command, teardown)) + if a:request.background - silent !screen -X other + let command = command + else + let command = 'screen -X eval "split" "focus down" "resize 10" "' . substitute(command, '"', '\"', '') . '" "focus up"' + endif + + call system(command) + + if !a:request.background + let s:waiting = a:request endif + return 1 endfunction @@ -42,3 +54,21 @@ function! dispatch#screen#activate(pid) abort return !v:shell_error endif endfunction + +function! dispatch#screen#poll() abort + if empty(s:waiting) + return + endif + + let pid = dispatch#pid(s:waiting) + if !pid + let request = s:waiting + 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 From eab7099f5ef0ba4d3a83fd4c961e1ec600a19d0c Mon Sep 17 00:00:00 2001 From: Rodrigo Moyle Date: Mon, 11 Aug 2014 19:22:26 -0300 Subject: [PATCH 2/4] Allow a second command to run synchronously. --- autoload/dispatch/screen.vim | 3 +++ 1 file changed, 3 insertions(+) diff --git a/autoload/dispatch/screen.vim b/autoload/dispatch/screen.vim index 422ffd35..3bfecacf 100644 --- a/autoload/dispatch/screen.vim +++ b/autoload/dispatch/screen.vim @@ -12,6 +12,9 @@ function! dispatch#screen#handle(request) abort return 0 endif if a:request.action ==# 'make' + if !get(a:request, 'background', 0) && empty(v:servername) && !empty(s:waiting) + return 0 + endif return dispatch#screen#spawn(dispatch#prepare_make(a:request), a:request) elseif a:request.action ==# 'start' return dispatch#screen#spawn(dispatch#prepare_start(a:request), a:request) From eddcfe7751dff17e186c815fbd7e8c61c5065fae Mon Sep 17 00:00:00 2001 From: Rodrigo Moyle Date: Tue, 12 Aug 2014 01:22:13 -0300 Subject: [PATCH 3/4] Porper escape of '"' on screen eval. --- autoload/dispatch/screen.vim | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/autoload/dispatch/screen.vim b/autoload/dispatch/screen.vim index 3bfecacf..cc5062a5 100644 --- a/autoload/dispatch/screen.vim +++ b/autoload/dispatch/screen.vim @@ -32,14 +32,10 @@ function! dispatch#screen#spawn(command, request) abort \ dispatch#set_title(a:request), a:command, teardown)) if a:request.background - let command = command + call system(command) else - let command = 'screen -X eval "split" "focus down" "resize 10" "' . substitute(command, '"', '\"', '') . '" "focus up"' - endif - - call system(command) - - if !a:request.background + let command = 'screen -X eval "split" "focus down" "resize 10" "' . escape(command, '"') . '" "focus up"' + call system(command) let s:waiting = a:request endif From 5fde25d397d44d921e315ccc405f2c4914f66bc9 Mon Sep 17 00:00:00 2001 From: Rodrigo Moyle Date: Tue, 12 Aug 2014 01:25:20 -0300 Subject: [PATCH 4/4] Trigger dispatch#complete when running a new command, to reset screen running poll. --- autoload/dispatch/screen.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/autoload/dispatch/screen.vim b/autoload/dispatch/screen.vim index cc5062a5..146f2ed7 100644 --- a/autoload/dispatch/screen.vim +++ b/autoload/dispatch/screen.vim @@ -11,6 +11,8 @@ function! dispatch#screen#handle(request) abort if empty($STY) || !executable('screen') return 0 endif + call dispatch#screen#poll() + if a:request.action ==# 'make' if !get(a:request, 'background', 0) && empty(v:servername) && !empty(s:waiting) return 0 @@ -59,8 +61,7 @@ function! dispatch#screen#poll() abort return endif - let pid = dispatch#pid(s:waiting) - if !pid + if !dispatch#pid(s:waiting) let request = s:waiting let s:waiting = {} call dispatch#complete(request)