From 00b5ae4e4043164879272ccde012a59892d9eae5 Mon Sep 17 00:00:00 2001 From: Chris Toomey Date: Sat, 26 Jan 2013 17:50:18 -0500 Subject: [PATCH] Accept optional new_percent arg to Resize command --- plugin/vim-tmux-runner.vim | 60 ++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/plugin/vim-tmux-runner.vim b/plugin/vim-tmux-runner.vim index 9169448..25bb5f5 100644 --- a/plugin/vim-tmux-runner.vim +++ b/plugin/vim-tmux-runner.vim @@ -122,33 +122,6 @@ function! s:RunnerPaneDimensions() endfor endfunction -function! s:ResizeRunnerPane() - if !s:RequireRunnerPane() - return - endif - let new_percent = s:HighlightedPrompt("Runner screen percentage: ") - let pane_dimensions = s:RunnerPaneDimensions() - let expand = (eval(join([new_percent, '>', s:vtr_percentage]))) - if s:vtr_orientation == "v" - let relevant_dimension = pane_dimensions['height'] - let direction = expand ? '-U' : '-D' - else - let relevant_dimension = pane_dimensions['width'] - let direction = expand ? '-L' : '-R' - endif - let inputs = [relevant_dimension, '*', new_percent, - \ '/', s:vtr_percentage] - let new_lines = eval(join(inputs)) " Not sure why I need to use eval...? - let lines_delta = abs(relevant_dimension - new_lines) - let targeted_cmd = s:TargetedTmuxCommand("resize-pane", s:runner_pane) - let full_command = join([targeted_cmd, direction, lines_delta]) - call s:SendTmuxCommand(full_command) - let s:vtr_percentage = new_percent - if g:VtrClearOnResize - call s:SendClearSequence() - endif -endfunction - function! s:FocusRunnerPane() call s:EnsureRunnerPane() call s:FocusTmuxPane(s:runner_pane) @@ -267,6 +240,37 @@ function! s:FlushCommand() endif endfunction +function! s:ResizeRunnerPane(...) + if !s:RequireRunnerPane() + return + endif + if exists("a:1") && a:1 != "" + let new_percent = shellescape(a:1) + else + let new_percent = s:HighlightedPrompt("Runner screen percentage: ") + endif + let pane_dimensions = s:RunnerPaneDimensions() + let expand = (eval(join([new_percent, '>', s:vtr_percentage]))) + if s:vtr_orientation == "v" + let relevant_dimension = pane_dimensions['height'] + let direction = expand ? '-U' : '-D' + else + let relevant_dimension = pane_dimensions['width'] + let direction = expand ? '-L' : '-R' + endif + let inputs = [relevant_dimension, '*', new_percent, + \ '/', s:vtr_percentage] + let new_lines = eval(join(inputs)) " Not sure why I need to use eval...? + let lines_delta = abs(relevant_dimension - new_lines) + let targeted_cmd = s:TargetedTmuxCommand("resize-pane", s:runner_pane) + let full_command = join([targeted_cmd, direction, lines_delta]) + call s:SendTmuxCommand(full_command) + let s:vtr_percentage = new_percent + if g:VtrClearOnResize + call s:SendClearSequence() + endif +endfunction + function! s:SendCommandToRunner(...) if exists("a:1") && a:1 != "" let s:user_command = shellescape(a:1) @@ -305,10 +309,10 @@ endfunction function! s:DefineCommands() command! -nargs=? VtrSendCommandToRunner call s:SendCommandToRunner() + command! -nargs=? VtrResizeRunner call s:ResizeRunnerPane() command! VtrOpenRunner :call s:EnsureRunnerPane() command! VtrKillRunner :call s:KillRunnerPane() command! VtrFocusRunner :call s:FocusRunnerPane() - command! VtrResizeRunner :call s:ResizeRunnerPane() command! VtrReorientRunner :call s:ReorientRunner() command! VtrDetachRunner :call s:DetachRunnerPane() command! VtrReattachRunner :call s:ReattachPane()