refactor: Simplify script-local private function names

fix-tmux-next-3dot4
Caleb Maclennan 3 years ago
parent 601749152e
commit 43681e9f91
No known key found for this signature in database
GPG Key ID: 63CC496475267693

@ -11,12 +11,12 @@ function! VimuxOption(option, default)
endif endif
endfunction endfunction
function! s:VimuxTmuxCmd() function! s:tmuxCmd()
return VimuxOption('g:VimuxTmuxCommand', 'tmux') return VimuxOption('g:VimuxTmuxCommand', 'tmux')
endfunction endfunction
if !executable(s:VimuxTmuxCmd()) if !executable(s:tmuxCmd())
echohl ErrorMsg | echomsg 'Failed to find executable '.s:VimuxTmuxCmd() | echohl None echohl ErrorMsg | echomsg 'Failed to find executable '.s:tmuxCmd() | echohl None
finish finish
endif endif
@ -51,7 +51,7 @@ function! VimuxRunLastCommand()
endfunction endfunction
function! VimuxRunCommand(command, ...) function! VimuxRunCommand(command, ...)
if !exists('g:VimuxRunnerIndex') || s:VimuxHasRunner(g:VimuxRunnerIndex) ==# -1 if !exists('g:VimuxRunnerIndex') || s:hasRunner(g:VimuxRunnerIndex) ==# -1
call VimuxOpenRunner() call VimuxOpenRunner()
endif endif
@ -77,47 +77,47 @@ endfunction
function! VimuxSendKeys(keys) function! VimuxSendKeys(keys)
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
call s:VimuxTmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys) call s:tmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys)
else else
echo 'No vimux runner pane/window. Create one with VimuxOpenRunner' echo 'No vimux runner pane/window. Create one with VimuxOpenRunner'
endif endif
endfunction endfunction
function! VimuxOpenRunner() function! VimuxOpenRunner()
let nearestIndex = s:VimuxNearestIndex() let nearestIndex = s:nearestIndex()
if VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1 if VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1
let g:VimuxRunnerIndex = nearestIndex let g:VimuxRunnerIndex = nearestIndex
else else
let extraArguments = VimuxOption('g:VimuxOpenExtraArgs', '') let extraArguments = VimuxOption('g:VimuxOpenExtraArgs', '')
if s:VimuxRunnerType() ==# 'pane' if s:runnerType() ==# 'pane'
let height = VimuxOption('g:VimuxHeight', 20) let height = VimuxOption('g:VimuxHeight', 20)
let orientation = VimuxOption('g:VimuxOrientation', 'v') let orientation = VimuxOption('g:VimuxOrientation', 'v')
call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments) call s:tmux('split-window -p '.height.' -'.orientation.' '.extraArguments)
elseif s:VimuxRunnerType() ==# 'window' elseif s:runnerType() ==# 'window'
call s:VimuxTmux('new-window '.extraArguments) call s:tmux('new-window '.extraArguments)
endif endif
let g:VimuxRunnerIndex = s:VimuxTmuxIndex() let g:VimuxRunnerIndex = s:tmuxIndex()
call s:VimuxSetRunnerName() call s:setRunnerName()
call s:VimuxTmux('last-'.s:VimuxRunnerType()) call s:tmux('last-'.s:runnerType())
endif endif
endfunction endfunction
function! VimuxCloseRunner() function! VimuxCloseRunner()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
call s:VimuxTmux('kill-'.s:VimuxRunnerType().' -t '.g:VimuxRunnerIndex) call s:tmux('kill-'.s:runnerType().' -t '.g:VimuxRunnerIndex)
unlet g:VimuxRunnerIndex unlet g:VimuxRunnerIndex
endif endif
endfunction endfunction
function! VimuxTogglePane() function! VimuxTogglePane()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
if s:VimuxRunnerType() ==# 'window' if s:runnerType() ==# 'window'
call s:VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('g:VimuxHeight', 20)) call s:tmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('g:VimuxHeight', 20))
let g:VimuxRunnerType = 'pane' let g:VimuxRunnerType = 'pane'
elseif s:VimuxRunnerType() ==# 'pane' elseif s:runnerType() ==# 'pane'
let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '') let g:VimuxRunnerIndex=substitute(s:tmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '')
let g:VimuxRunnerType = 'window' let g:VimuxRunnerType = 'window'
endif endif
endif endif
@ -125,28 +125,28 @@ endfunction
function! VimuxZoomRunner() function! VimuxZoomRunner()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
if s:VimuxRunnerType() ==# 'pane' if s:runnerType() ==# 'pane'
call s:VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex) call s:tmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
elseif s:VimuxRunnerType() ==# 'window' elseif s:runnerType() ==# 'window'
call s:VimuxTmux('select-window -t '.g:VimuxRunnerIndex) call s:tmux('select-window -t '.g:VimuxRunnerIndex)
endif endif
endif endif
endfunction endfunction
function! VimuxInspectRunner() function! VimuxInspectRunner()
call s:VimuxTmux('select-'.s:VimuxRunnerType().' -t '.g:VimuxRunnerIndex) call s:tmux('select-'.s:runnerType().' -t '.g:VimuxRunnerIndex)
call s:VimuxTmux('copy-mode') call s:tmux('copy-mode')
endfunction endfunction
function! VimuxScrollUpInspect() function! VimuxScrollUpInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call s:VimuxTmux('last-'.s:VimuxRunnerType()) call s:tmux('last-'.s:runnerType())
call VimuxSendKeys('C-u') call VimuxSendKeys('C-u')
endfunction endfunction
function! VimuxScrollDownInspect() function! VimuxScrollDownInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call s:VimuxTmux('last-'.s:VimuxRunnerType()) call s:tmux('last-'.s:runnerType())
call VimuxSendKeys('C-d') call VimuxSendKeys('C-d')
endfunction endfunction
@ -162,7 +162,7 @@ endfunction
function! VimuxClearRunnerHistory() function! VimuxClearRunnerHistory()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
call s:VimuxTmux('clear-history -t '.g:VimuxRunnerIndex) call s:tmux('clear-history -t '.g:VimuxRunnerIndex)
endif endif
endfunction endfunction
@ -172,37 +172,37 @@ function! VimuxPromptCommand(...)
call VimuxRunCommand(l:command) call VimuxRunCommand(l:command)
endfunction endfunction
function! s:VimuxTmux(arguments) function! s:tmux(arguments)
if VimuxOption('g:VimuxDebug', 0) != 0 if VimuxOption('g:VimuxDebug', 0) != 0
echom s:VimuxTmuxCmd().' '.a:arguments echom s:tmuxCmd().' '.a:arguments
endif endif
return system(s:VimuxTmuxCmd().' '.a:arguments) return system(s:tmuxCmd().' '.a:arguments)
endfunction endfunction
function! s:VimuxTmuxSession() function! s:tmuxSession()
return s:VimuxTmuxProperty('#S') return s:tmuxProperty('#S')
endfunction endfunction
function! s:VimuxTmuxIndex() function! s:tmuxIndex()
if s:VimuxRunnerType() ==# 'pane' if s:runnerType() ==# 'pane'
return s:VimuxTmuxPaneId() return s:tmuxPaneId()
else else
return s:VimuxTmuxWindowId() return s:tmuxWindowId()
end end
endfunction endfunction
function! s:VimuxTmuxPaneId() function! s:tmuxPaneId()
return s:VimuxTmuxProperty('#{pane_id}') return s:tmuxProperty('#{pane_id}')
endfunction endfunction
function! s:VimuxTmuxWindowId() function! s:tmuxWindowId()
return s:VimuxTmuxProperty('#{window_id}') return s:tmuxProperty('#{window_id}')
endfunction endfunction
function! s:VimuxNearestIndex() function! s:nearestIndex()
let t = s:VimuxRunnerType() let t = s:runnerType()
let filter = s:VimuxGetTargetFilter() let filter = s:getTargetFilter()
let views = split(s:VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n') let views = split(s:tmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n')
for view in views for view in views
if match(view, '1:') ==# -1 if match(view, '1:') ==# -1
@ -213,12 +213,12 @@ function! s:VimuxNearestIndex()
return -1 return -1
endfunction endfunction
function! s:VimuxGetTargetFilter() function! s:getTargetFilter()
let targetName = VimuxOption('g:VimuxRunnerName', '') let targetName = VimuxOption('g:VimuxRunnerName', '')
if targetName ==# '' if targetName ==# ''
return '' return ''
endif endif
let t = s:VimuxRunnerType() let t = s:runnerType()
if t ==# 'window' if t ==# 'window'
return " -f '#{==:#{window_name},".targetName."}'" return " -f '#{==:#{window_name},".targetName."}'"
elseif t ==# 'pane' elseif t ==# 'pane'
@ -226,29 +226,29 @@ function! s:VimuxGetTargetFilter()
endif endif
endfunction endfunction
function! s:VimuxSetRunnerName() function! s:setRunnerName()
let targetName = VimuxOption('g:VimuxRunnerName', '') let targetName = VimuxOption('g:VimuxRunnerName', '')
if targetName ==# '' if targetName ==# ''
return return
endif endif
let t = s:VimuxRunnerType() let t = s:runnerType()
if t ==# 'window' if t ==# 'window'
call s:VimuxTmux('rename-window '.targetName) call s:tmux('rename-window '.targetName)
elseif t ==# 'pane' elseif t ==# 'pane'
call s:VimuxTmux('select-pane -T '.targetName) call s:tmux('select-pane -T '.targetName)
endif endif
endfunction endfunction
function! s:VimuxRunnerType() function! s:runnerType()
return VimuxOption('g:VimuxRunnerType', 'pane') return VimuxOption('g:VimuxRunnerType', 'pane')
endfunction endfunction
function! s:VimuxTmuxProperty(property) function! s:tmuxProperty(property)
return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '') return substitute(s:tmux("display -p '".a:property."'"), '\n$', '', '')
endfunction endfunction
function! s:VimuxHasRunner(index) function! s:hasRunner(index)
let t = s:VimuxRunnerType() let t = s:runnerType()
return match(s:VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index) return match(s:tmux('list-'.t."s -F '#{".t."_id}'"), a:index)
endfunction endfunction

Loading…
Cancel
Save