Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 24 additions & 60 deletions plugin/vimux.vim
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,18 @@ function! VimuxOpenRunner() abort
elseif VimuxOption('VimuxRunnerType') ==# 'window'
call VimuxTmux('new-window '.extraArguments)
endif
let g:VimuxRunnerIndex = s:tmuxIndex()
call s:setRunnerName()
let g:VimuxRunnerIndex = s:tmuxProperty('#{pane_id}')
let targetName = VimuxOption('VimuxRunnerName')
if targetName !=# ''
call VimuxTmux('select-pane -T '.targetName)
endif
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
endif
endfunction

function! VimuxCloseRunner() abort
if s:hasRunner()
call VimuxTmux('kill-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
call VimuxTmux('kill-pane -t '.g:VimuxRunnerIndex)
endif
unlet! g:VimuxRunnerIndex
endfunction
Expand All @@ -128,15 +131,9 @@ function! VimuxTogglePane() abort
if VimuxOption('VimuxRunnerType') ==# 'window'
call VimuxTmux('join-pane -s '.g:VimuxRunnerIndex.' '.s:vimuxPaneOptions())
let g:VimuxRunnerType = 'pane'
let g:VimuxRunnerIndex = s:tmuxIndex()
call VimuxTmux('last-'.VimuxOption('VimuxRunnerType'))
call VimuxTmux('last-pane')
elseif VimuxOption('VimuxRunnerType') ==# 'pane'
let g:VimuxRunnerIndex=substitute(
\ VimuxTmux('break-pane -d -s '.g:VimuxRunnerIndex." -P -F '#{window_id}'"),
\ '\n',
\ '',
\ ''
\)
call VimuxTmux('break-pane -d -s '.g:VimuxRunnerIndex)
let g:VimuxRunnerType = 'window'
endif
else
Expand All @@ -146,19 +143,16 @@ endfunction

function! VimuxZoomRunner() abort
if s:hasRunner()
if VimuxOption('VimuxRunnerType') ==# 'pane'
call VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
elseif VimuxOption('VimuxRunnerType') ==# 'window'
call VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
endif
call s:selectRunner()
call VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
else
call s:echoNoRunner()
endif
endfunction

function! VimuxInspectRunner() abort
if s:hasRunner()
call VimuxTmux('select-'.VimuxOption('VimuxRunnerType').' -t '.g:VimuxRunnerIndex)
call s:selectRunner()
call VimuxTmux('copy-mode')
return v:true
endif
Expand Down Expand Up @@ -234,6 +228,11 @@ function! VimuxTmux(arguments) abort
endif
endfunction

function! s:selectRunner() abort
call VimuxTmux('select-window -t '.g:VimuxRunnerIndex)
call VimuxTmux('select-pane -t '.g:VimuxRunnerIndex)
endfunction

function! s:exitCopyMode() abort
try
call VimuxTmux('copy-mode -q -t '.g:VimuxRunnerIndex)
Expand All @@ -245,35 +244,15 @@ function! s:exitCopyMode() abort
endtry
endfunction

function! s:tmuxSession() abort
return s:tmuxProperty('#S')
endfunction

function! s:tmuxIndex() abort
if VimuxOption('VimuxRunnerType') ==# 'pane'
return s:tmuxPaneId()
else
return s:tmuxWindowId()
end
endfunction

function! s:tmuxPaneId() abort
return s:tmuxProperty('#{pane_id}')
endfunction

function! s:tmuxWindowId() abort
return s:tmuxProperty('#{window_id}')
endfunction

function! s:vimuxPaneOptions() abort
let height = VimuxOption('VimuxHeight')
let orientation = VimuxOption('VimuxOrientation')
return '-l '.height.' -'.orientation
endfunction

""
" @return a string of the form '%4', the ID of the pane or window to use,
" or '' if no nearest pane or window is found.
" @return a string of the form '%4', the ID of the pane to use,
" or '' if no nearest pane is found.
function! s:existingRunnerId() abort
let runnerType = VimuxOption('VimuxRunnerType')
let query = get(VimuxOption('VimuxRunnerQuery'), runnerType, '')
Expand All @@ -285,12 +264,11 @@ function! s:existingRunnerId() abort
endif
endif
" Try finding the runner using the provided query
let currentId = s:tmuxIndex()
let currentId = s:tmuxProperty('#{pane_id}')
let message = VimuxTmux('select-'.runnerType.' -t '.query.'')
if message ==# ''
" A match was found. Make sure it isn't the current vim pane/window
" though!
let runnerId = s:tmuxIndex()
" A match was found. Make sure it isn't the current vim pane!
let runnerId = s:tmuxProperty('#{pane_id}')
if runnerId !=# currentId
" Success!
call VimuxTmux('last-'.runnerType)
Expand All @@ -308,7 +286,7 @@ function! s:nearestRunnerId() abort
let views = split(
\ VimuxTmux(
\ 'list-'.runnerType.'s'
\ ." -F '#{".runnerType.'_active}:#{'.runnerType."_id}'"
\ ." -F '#{".runnerType.'_active}:#{pane_id}"'
\ .filter),
\ '\n')
" '1:' is the current active pane (the one with vim).
Expand All @@ -334,19 +312,6 @@ function! s:getTargetFilter() abort
endif
endfunction

function! s:setRunnerName() abort
let targetName = VimuxOption('VimuxRunnerName')
if targetName ==# ''
return
endif
let runnerType = VimuxOption('VimuxRunnerType')
if runnerType ==# 'window'
call VimuxTmux('rename-window '.targetName)
elseif runnerType ==# 'pane'
call VimuxTmux('select-pane -T '.targetName)
endif
endfunction

function! s:tmuxProperty(property) abort
return substitute(VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
endfunction
Expand All @@ -355,9 +320,8 @@ function! s:hasRunner() abort
if get(g:, 'VimuxRunnerIndex', '') ==? ''
return v:false
endif
let l:runnerType = VimuxOption('VimuxRunnerType')
let l:command = 'list-'.runnerType."s -F '#{".runnerType."_id}'"
let l:found = match(VimuxTmux(l:command), g:VimuxRunnerIndex)
let l:command = "list-panes -a -F '#{pane_id}'"
let l:found = match(VimuxTmux(l:command), g:VimuxRunnerIndex.'\>')
return l:found != -1
endfunction

Expand Down
Loading