diff --git a/plugin/vimux.vim b/plugin/vimux.vim index b5000a7..80549ca 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -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 @@ -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 @@ -146,11 +143,8 @@ 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 @@ -158,7 +152,7 @@ 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 @@ -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) @@ -245,26 +244,6 @@ 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') @@ -272,8 +251,8 @@ function! s:vimuxPaneOptions() abort 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, '') @@ -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) @@ -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). @@ -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 @@ -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