From 60bb1622d4b061caa1c3349ea5986cd9e1c3f229 Mon Sep 17 00:00:00 2001 From: Chris Toomey Date: Thu, 29 Nov 2012 19:21:46 -0500 Subject: [PATCH] Create runner pane in temp window In order to avoid rapid flickering of runner window as it is created and initialized, create and initialize it in a temporary background window then bring it in. --- doc/vim-tmux-runner.txt | 17 +++++++++++++++++ plugin/vim-tmux-runner.vim | 29 ++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/doc/vim-tmux-runner.txt b/doc/vim-tmux-runner.txt index 2980e4a..6ef0c1d 100644 --- a/doc/vim-tmux-runner.txt +++ b/doc/vim-tmux-runner.txt @@ -33,6 +33,7 @@ CONTENTS *vtr-contents* 3.9 ................................ |VtrClearOnReattach| 3.10 ............................... |VtrDetachedName| 3.11 ............................... |VtrClearSequence| + 3.12 ............................... |VtrInitTimeout| ============================================================================== ABOUT (1) *VTR-About* @@ -344,5 +345,21 @@ insert mode. See the help file, ':help i_Ctrl-v', for more detail. Default: " " +------------------------------------------------------------------------------ + *VtrInitTimeout* +3.12 g:VtrInitTimeout~ + +Timeout in milliseconds to use when initializing the runner in temporary +window. This is intended to provide the runner sufficient time to run the +initializing commands and then be attached to the Vim window. + +This timeout is only relevant if VTR is configured to cd to the git root, or +run an initial command. These can be set through their respective +configuration options, |g:VtrGitCdUpOnOpen| and |g:VtrInitialCommand|. + + let g:VtrInitTimeout = 100 + +Default: 500 + ============================================================================== vim:tw=78:ts=2:sw=2:expandtab:ft=help:norl: diff --git a/plugin/vim-tmux-runner.vim b/plugin/vim-tmux-runner.vim index 022580b..ba111f3 100644 --- a/plugin/vim-tmux-runner.vim +++ b/plugin/vim-tmux-runner.vim @@ -12,16 +12,29 @@ endfunction function! s:OpenRunnerPane() let s:vim_pane = s:ActiveTmuxPaneNumber() - let cmd = join(["split-window -p", s:vtr_percentage, "-".s:vtr_orientation]) - call s:SendTmuxCommand(cmd) - let s:runner_pane = s:ActiveTmuxPaneNumber() - call s:FocusVimPane() + let remote_cmd = join(["new-window", "-d", "-n", g:VtrDetachedName]) + call s:SendTmuxCommand(remote_cmd) + let [s:detached_window, s:runner_pane] = [s:LastWindowNumber(), 0] if g:VtrGitCdUpOnOpen call s:GitCdUp() endif if g:VtrInitialCommand != "" call s:SendKeys(g:VtrInitialCommand) endif + if g:VtrInitialCommand || g:VtrGitCdUpOnOpen + call s:TimeoutWithProgess() + endif + call s:ReattachPane() +endfunction + +function! s:TimeoutWithProgess() + let timeout_portion = g:VtrInitTimeout / 3 + echohl String | echon 'Preparing runner.' + for time in [1,2,3] + execute join(['sleep', timeout_portion.'m']) + echon '.' + endfor + echohl None endfunction function! s:DetachRunnerPane() @@ -147,7 +160,12 @@ function! s:SendTmuxCommand(command) endfunction function! s:TargetedTmuxCommand(command, target_pane) - return a:command . " -t " . a:target_pane + if exists("s:detached_window") + let target = ':'.s:detached_window.'.'.a:target_pane + else + let target = a:target_pane + endif + return join([a:command, " -t ", target]) endfunction function! s:_SendKeys(keys) @@ -325,6 +343,7 @@ function! s:InitializeVariables() call s:InitVariable("g:VtrClearOnReorient", 1) call s:InitVariable("g:VtrClearOnReattach", 1) call s:InitVariable("g:VtrDetachedName", "VTR_Pane") + call s:InitVariable("g:VtrInitTimeout", 450) call s:InitVariable("g:VtrClearSequence", " ") let s:vtr_percentage = g:VtrPercentage let s:vtr_orientation = g:VtrOrientation