From 49a048e94e6a027f485420a63d6c930523fc57b1 Mon Sep 17 00:00:00 2001 From: Ryan Glover Date: Sat, 28 Sep 2013 16:32:35 -0400 Subject: [PATCH 1/3] Change variable and function names to be pane/window agnostic --- plugin/vimux.vim | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 0459b3b..3a698da 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -13,7 +13,7 @@ command VimuxPromptCommand :call VimuxPromptCommand() command VimuxClearRunnerHistory :call VimuxClearRunnerHistory() function! VimuxRunLastCommand() - if exists("g:VimuxRunnerPaneIndex") + if exists("g:VimuxRunnerIndex") call VimuxRunCommand(g:VimuxLastCommand) else echo "No last vimux command." @@ -21,8 +21,8 @@ function! VimuxRunLastCommand() endfunction function! VimuxRunCommand(command, ...) - if !exists("g:VimuxRunnerPaneIndex") || _VimuxHasPane(g:VimuxRunnerPaneIndex) == -1 - call VimuxOpenPane() + if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1 + call VimuxOpenRunner() endif let l:autoreturn = 1 @@ -46,36 +46,36 @@ function! VimuxSendText(text) endfunction function! VimuxSendKeys(keys) - if exists("g:VimuxRunnerPaneIndex") - call system("tmux send-keys -t ".g:VimuxRunnerPaneIndex." ".a:keys) + if exists("g:VimuxRunnerIndex") + call system("tmux send-keys -t ".g:VimuxRunnerIndex." ".a:keys) else - echo "No vimux runner pane. Create one with VimuxOpenPane" + echo "No vimux runner pane/window. Create one with VimuxOpenRunner" endif endfunction -function! VimuxOpenPane() +function! VimuxOpenRunner() let height = _VimuxOption("g:VimuxHeight", 20) let orientation = _VimuxOption("g:VimuxOrientation", "v") - let nearestIndex = _VimuxNearestPaneIndex() + let nearestIndex = _VimuxNearestIndex() - if _VimuxOption("g:VimuxUseNearestPane", 1) == 1 && nearestIndex != -1 - let g:VimuxRunnerPaneIndex = nearestIndex + if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1 + let g:VimuxRunnerIndex = nearestIndex else call system("tmux split-window -p ".height." -".orientation) - let g:VimuxRunnerPaneIndex = _VimuxTmuxPaneIndex() + let g:VimuxRunnerIndex = _VimuxTmuxIndex() call system("tmux last-pane") endif endfunction function! VimuxCloseRunner() - if exists("g:VimuxRunnerPaneIndex") - call system("tmux kill-pane -t ".g:VimuxRunnerPaneIndex) - unlet g:VimuxRunnerPaneIndex + if exists("g:VimuxRunnerIndex") + call system("tmux kill-pane -t ".g:VimuxRunnerIndex) + unlet g:VimuxRunnerIndex endif endfunction function! VimuxInspectRunner() - call system("tmux select-pane -t ".g:VimuxRunnerPaneIndex) + call system("tmux select-pane -t ".g:VimuxRunnerIndex) call system("tmux copy-mode") endfunction @@ -96,8 +96,8 @@ function! VimuxInterruptRunner() endfunction function! VimuxClearRunnerHistory() - if exists("g:VimuxRunnerPaneIndex") - call system("tmux clear-history -t ".g:VimuxRunnerPaneIndex) + if exists("g:VimuxRunnerIndex") + call system("tmux clear-history -t ".g:VimuxRunnerIndex) endif endfunction @@ -110,7 +110,7 @@ function! _VimuxTmuxSession() return _VimuxTmuxProperty("S") endfunction -function! _VimuxTmuxPaneIndex() +function! _VimuxTmuxIndex() return _VimuxTmuxProperty("P") endfunction @@ -118,7 +118,7 @@ function! _VimuxTmuxWindowIndex() return _VimuxTmuxProperty("I") endfunction -function! _VimuxNearestPaneIndex() +function! _VimuxNearestIndex() let panes = split(system("tmux list-panes"), "\n") for pane in panes @@ -142,6 +142,6 @@ function! _VimuxTmuxProperty(property) return substitute(system("tmux display -p '#".a:property."'"), '\n$', '', '') endfunction -function! _VimuxHasPane(index) +function! _VimuxHasRunner(index) return match(system("tmux list-panes"), a:index.":") endfunction From aa8a444609b20b7f92fa721959fccb29fc826c02 Mon Sep 17 00:00:00 2001 From: Ryan Glover Date: Sat, 28 Sep 2013 17:14:41 -0400 Subject: [PATCH 2/3] Add ability to change runner type between pane and window --- plugin/vimux.vim | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 3a698da..0b02b38 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -63,31 +63,31 @@ function! VimuxOpenRunner() else call system("tmux split-window -p ".height." -".orientation) let g:VimuxRunnerIndex = _VimuxTmuxIndex() - call system("tmux last-pane") + call system("tmux last-"._VimuxRunnerType()) endif endfunction function! VimuxCloseRunner() if exists("g:VimuxRunnerIndex") - call system("tmux kill-pane -t ".g:VimuxRunnerIndex) + call system("tmux kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) unlet g:VimuxRunnerIndex endif endfunction function! VimuxInspectRunner() - call system("tmux select-pane -t ".g:VimuxRunnerIndex) + call system("tmux select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) call system("tmux copy-mode") endfunction function! VimuxScrollUpInspect() call VimuxInspectRunner() - call system("tmux last-pane") + call system("tmux last-"._VimuxRunnerType()) call VimuxSendKeys("C-u") endfunction function! VimuxScrollDownInspect() call VimuxInspectRunner() - call system("tmux last-pane") + call system("tmux last-"._VimuxRunnerType()) call VimuxSendKeys("C-d") endfunction @@ -119,7 +119,7 @@ function! _VimuxTmuxWindowIndex() endfunction function! _VimuxNearestIndex() - let panes = split(system("tmux list-panes"), "\n") + let panes = split(system("tmux list-"._VimuxRunnerType()."s"), "\n") for pane in panes if match(pane, "(active)") == -1 @@ -130,6 +130,10 @@ function! _VimuxNearestIndex() return -1 endfunction +function! _VimuxRunnerType() + return _VimuxOption("g:VimuxRunnerType", "pane") +endfunction + function! _VimuxOption(option, default) if exists(a:option) return eval(a:option) @@ -143,5 +147,5 @@ function! _VimuxTmuxProperty(property) endfunction function! _VimuxHasRunner(index) - return match(system("tmux list-panes"), a:index.":") + return match(system("tmux list-"._VimuxRunnerType()."s"), a:index.":") endfunction From 7212ae4ee86d9c5f4ad5288c6dd1639c2434d1e2 Mon Sep 17 00:00:00 2001 From: Ryan Glover Date: Sat, 28 Sep 2013 17:26:59 -0400 Subject: [PATCH 3/3] Fix finding index to be based on runner type --- plugin/vimux.vim | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 0b02b38..78c7cb2 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -54,14 +54,19 @@ function! VimuxSendKeys(keys) endfunction function! VimuxOpenRunner() - let height = _VimuxOption("g:VimuxHeight", 20) - let orientation = _VimuxOption("g:VimuxOrientation", "v") let nearestIndex = _VimuxNearestIndex() if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1 let g:VimuxRunnerIndex = nearestIndex else - call system("tmux split-window -p ".height." -".orientation) + if _VimuxRunnerType() == "pane" + let height = _VimuxOption("g:VimuxHeight", 20) + let orientation = _VimuxOption("g:VimuxOrientation", "v") + call system("tmux split-window -p ".height." -".orientation) + elseif _VimuxRunnerType() == "window" + call system("tmux new-window") + endif + let g:VimuxRunnerIndex = _VimuxTmuxIndex() call system("tmux last-"._VimuxRunnerType()) endif @@ -111,7 +116,15 @@ function! _VimuxTmuxSession() endfunction function! _VimuxTmuxIndex() - return _VimuxTmuxProperty("P") + if _VimuxRunnerType == "pane" + return _VimuxTmuxPaneIndex() + else + return _VimuxTmuxWindowIndex() + end +endfunction + +function! _VimuxTmuxPaneIndex() + return _VimuxTmuxProperty("P") endfunction function! _VimuxTmuxWindowIndex()