Merge pull request #83 from ersatzryan/master

Ability to change runner type
fix-tmux-next-3dot4
Ben Mills 11 years ago
commit 1e30ed8065

@ -14,7 +14,7 @@ command VimuxPromptCommand :call VimuxPromptCommand()
command VimuxClearRunnerHistory :call VimuxClearRunnerHistory() command VimuxClearRunnerHistory :call VimuxClearRunnerHistory()
function! VimuxRunLastCommand() function! VimuxRunLastCommand()
if exists("g:VimuxRunnerPaneIndex") if exists("g:VimuxRunnerIndex")
call VimuxRunCommand(g:VimuxLastCommand) call VimuxRunCommand(g:VimuxLastCommand)
else else
echo "No last vimux command." echo "No last vimux command."
@ -22,8 +22,8 @@ function! VimuxRunLastCommand()
endfunction endfunction
function! VimuxRunCommand(command, ...) function! VimuxRunCommand(command, ...)
if !exists("g:VimuxRunnerPaneIndex") || _VimuxHasPane(g:VimuxRunnerPaneIndex) == -1 if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1
call VimuxOpenPane() call VimuxOpenRunner()
endif endif
let l:autoreturn = 1 let l:autoreturn = 1
@ -47,31 +47,36 @@ function! VimuxSendText(text)
endfunction endfunction
function! VimuxSendKeys(keys) function! VimuxSendKeys(keys)
if exists("g:VimuxRunnerPaneIndex") if exists("g:VimuxRunnerIndex")
call system("tmux send-keys -t ".g:VimuxRunnerPaneIndex." ".a:keys) call system("tmux send-keys -t ".g:VimuxRunnerIndex." ".a:keys)
else else
echo "No vimux runner pane. Create one with VimuxOpenPane" echo "No vimux runner pane/window. Create one with VimuxOpenRunner"
endif endif
endfunction endfunction
function! VimuxOpenPane() function! VimuxOpenRunner()
let height = _VimuxOption("g:VimuxHeight", 20) let nearestIndex = _VimuxNearestIndex()
let orientation = _VimuxOption("g:VimuxOrientation", "v")
let nearestIndex = _VimuxNearestPaneIndex()
if _VimuxOption("g:VimuxUseNearestPane", 1) == 1 && nearestIndex != -1 if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
let g:VimuxRunnerPaneIndex = nearestIndex let g:VimuxRunnerIndex = nearestIndex
else else
call system("tmux split-window -p ".height." -".orientation) if _VimuxRunnerType() == "pane"
let g:VimuxRunnerPaneIndex = _VimuxTmuxPaneIndex() let height = _VimuxOption("g:VimuxHeight", 20)
call system("tmux last-pane") 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 endif
endfunction endfunction
function! VimuxCloseRunner() function! VimuxCloseRunner()
if exists("g:VimuxRunnerPaneIndex") if exists("g:VimuxRunnerIndex")
call system("tmux kill-pane -t ".g:VimuxRunnerPaneIndex) call system("tmux kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
unlet g:VimuxRunnerPaneIndex unlet g:VimuxRunnerIndex
endif endif
endfunction endfunction
@ -83,19 +88,19 @@ function! VimuxZoomRunner()
endfunction endfunction
function! VimuxInspectRunner() function! VimuxInspectRunner()
call system("tmux select-pane -t ".g:VimuxRunnerPaneIndex) call system("tmux select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
call system("tmux copy-mode") call system("tmux copy-mode")
endfunction endfunction
function! VimuxScrollUpInspect() function! VimuxScrollUpInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call system("tmux last-pane") call system("tmux last-"._VimuxRunnerType())
call VimuxSendKeys("C-u") call VimuxSendKeys("C-u")
endfunction endfunction
function! VimuxScrollDownInspect() function! VimuxScrollDownInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call system("tmux last-pane") call system("tmux last-"._VimuxRunnerType())
call VimuxSendKeys("C-d") call VimuxSendKeys("C-d")
endfunction endfunction
@ -104,8 +109,8 @@ function! VimuxInterruptRunner()
endfunction endfunction
function! VimuxClearRunnerHistory() function! VimuxClearRunnerHistory()
if exists("g:VimuxRunnerPaneIndex") if exists("g:VimuxRunnerIndex")
call system("tmux clear-history -t ".g:VimuxRunnerPaneIndex) call system("tmux clear-history -t ".g:VimuxRunnerIndex)
endif endif
endfunction endfunction
@ -118,16 +123,24 @@ function! _VimuxTmuxSession()
return _VimuxTmuxProperty("S") return _VimuxTmuxProperty("S")
endfunction endfunction
function! _VimuxTmuxIndex()
if _VimuxRunnerType == "pane"
return _VimuxTmuxPaneIndex()
else
return _VimuxTmuxWindowIndex()
end
endfunction
function! _VimuxTmuxPaneIndex() function! _VimuxTmuxPaneIndex()
return _VimuxTmuxProperty("P") return _VimuxTmuxProperty("P")
endfunction endfunction
function! _VimuxTmuxWindowIndex() function! _VimuxTmuxWindowIndex()
return _VimuxTmuxProperty("I") return _VimuxTmuxProperty("I")
endfunction endfunction
function! _VimuxNearestPaneIndex() function! _VimuxNearestIndex()
let panes = split(system("tmux list-panes"), "\n") let panes = split(system("tmux list-"._VimuxRunnerType()."s"), "\n")
for pane in panes for pane in panes
if match(pane, "(active)") == -1 if match(pane, "(active)") == -1
@ -138,6 +151,10 @@ function! _VimuxNearestPaneIndex()
return -1 return -1
endfunction endfunction
function! _VimuxRunnerType()
return _VimuxOption("g:VimuxRunnerType", "pane")
endfunction
function! _VimuxOption(option, default) function! _VimuxOption(option, default)
if exists(a:option) if exists(a:option)
return eval(a:option) return eval(a:option)
@ -150,6 +167,6 @@ function! _VimuxTmuxProperty(property)
return substitute(system("tmux display -p '#".a:property."'"), '\n$', '', '') return substitute(system("tmux display -p '#".a:property."'"), '\n$', '', '')
endfunction endfunction
function! _VimuxHasPane(index) function! _VimuxHasRunner(index)
return match(system("tmux list-panes"), a:index.":") return match(system("tmux list-"._VimuxRunnerType()."s"), a:index.":")
endfunction endfunction

Loading…
Cancel
Save