Define options once at startup

This also removes a couple of "getter" functions that were being used to
look up options and fall back to their defaults
fix-tmux-next-3dot4
Michael van der Kamp 3 years ago committed by Caleb Maclennan
parent 5f999f4dc4
commit 748b54b885
No known key found for this signature in database
GPG Key ID: 63CC496475267693

@ -3,20 +3,20 @@ if exists('g:loaded_vimux') || &compatible
endif endif
let g:loaded_vimux = 1 let g:loaded_vimux = 1
function! s:VimuxOption(option, default) " Set up all global options with defaults right away, in one place
if exists(a:option) let g:VimuxDebug = get(g:, 'VimuxDebug', v:false)
return eval(a:option) let g:VimuxHeight = get(g:, 'VimuxHeight', 20)
else let g:VimuxOpenExtraArgs = get(g:, 'VimuxOpenExtraArgs', '')
return a:default let g:VimuxOrientation = get(g:, 'VimuxOrientation', 'v')
endif let g:VimuxPromptString = get(g:, 'VimuxPromptString', 'Command? ')
endfunction let g:VimuxResetSequence = get(g:, 'VimuxResetSequence', 'q C-u')
let g:VimuxRunnerName = get(g:, 'VimuxRunnerName', '')
function! s:VimuxTmuxCmd() let g:VimuxRunnerType = get(g:, 'VimuxRunnerType', 'pane')
return s:VimuxOption('g:VimuxTmuxCommand', 'tmux') let g:VimuxTmuxCommand = get(g:, 'VimuxTmuxCommand', 'tmux')
endfunction let g:VimuxUseNearest = get(g:, 'VimuxUseNearest', v:true)
if !executable(s:VimuxTmuxCmd()) if !executable(g:VimuxTmuxCommand)
echohl ErrorMsg | echomsg 'Failed to find executable '.s:VimuxTmuxCmd() | echohl None echohl ErrorMsg | echomsg 'Failed to find executable '.g:VimuxTmuxCommand | echohl None
finish finish
endif endif
@ -60,7 +60,7 @@ function! VimuxRunCommand(command, ...)
let l:autoreturn = a:1 let l:autoreturn = a:1
endif endif
let resetSequence = s:VimuxOption('g:VimuxResetSequence', 'q C-u') let resetSequence = g:VimuxResetSequence
let g:VimuxLastCommand = a:command let g:VimuxLastCommand = a:command
call VimuxSendKeys(resetSequence) call VimuxSendKeys(resetSequence)
@ -86,37 +86,37 @@ endfunction
function! VimuxOpenRunner() function! VimuxOpenRunner()
let nearestIndex = s:VimuxNearestIndex() let nearestIndex = s:VimuxNearestIndex()
if s:VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1 if g:VimuxUseNearest ==# 1 && nearestIndex != -1
let g:VimuxRunnerIndex = nearestIndex let g:VimuxRunnerIndex = nearestIndex
else else
let extraArguments = s:VimuxOption('g:VimuxOpenExtraArgs', '') let extraArguments = g:VimuxOpenExtraArgs
if s:VimuxRunnerType() ==# 'pane' if g:VimuxRunnerType ==# 'pane'
let height = s:VimuxOption('g:VimuxHeight', 20) let height = g:VimuxHeight
let orientation = s:VimuxOption('g:VimuxOrientation', 'v') let orientation = g:VimuxOrientation
call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments) call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments)
elseif s:VimuxRunnerType() ==# 'window' elseif g:VimuxRunnerType ==# 'window'
call s:VimuxTmux('new-window '.extraArguments) call s:VimuxTmux('new-window '.extraArguments)
endif endif
let g:VimuxRunnerIndex = s:VimuxTmuxIndex() let g:VimuxRunnerIndex = s:VimuxTmuxIndex()
call s:VimuxSetRunnerName() call s:VimuxSetRunnerName()
call s:VimuxTmux('last-'.s:VimuxRunnerType()) call s:VimuxTmux('last-'.g:VimuxRunnerType)
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:VimuxTmux('kill-'.g:VimuxRunnerType.' -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 g:VimuxRunnerType ==# 'window'
call s:VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.s:VimuxOption('g:VimuxHeight', 20)) call s:VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.g:VimuxHeight)
let g:VimuxRunnerType = 'pane' let g:VimuxRunnerType = 'pane'
elseif s:VimuxRunnerType() ==# 'pane' elseif g:VimuxRunnerType ==# 'pane'
let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '') let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '')
let g:VimuxRunnerType = 'window' let g:VimuxRunnerType = 'window'
endif endif
@ -125,28 +125,28 @@ endfunction
function! VimuxZoomRunner() function! VimuxZoomRunner()
if exists('g:VimuxRunnerIndex') if exists('g:VimuxRunnerIndex')
if s:VimuxRunnerType() ==# 'pane' if g:VimuxRunnerType ==# 'pane'
call s:VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex) call s:VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex)
elseif s:VimuxRunnerType() ==# 'window' elseif g:VimuxRunnerType ==# 'window'
call s:VimuxTmux('select-window -t '.g:VimuxRunnerIndex) call s:VimuxTmux('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:VimuxTmux('select-'.g:VimuxRunnerType.' -t '.g:VimuxRunnerIndex)
call s:VimuxTmux('copy-mode') call s:VimuxTmux('copy-mode')
endfunction endfunction
function! VimuxScrollUpInspect() function! VimuxScrollUpInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call s:VimuxTmux('last-'.s:VimuxRunnerType()) call s:VimuxTmux('last-'.g:VimuxRunnerType)
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:VimuxTmux('last-'.g:VimuxRunnerType)
call VimuxSendKeys('C-d') call VimuxSendKeys('C-d')
endfunction endfunction
@ -168,15 +168,15 @@ endfunction
function! VimuxPromptCommand(...) function! VimuxPromptCommand(...)
let command = a:0 ==# 1 ? a:1 : '' let command = a:0 ==# 1 ? a:1 : ''
let l:command = input(s:VimuxOption('g:VimuxPromptString', 'Command? '), command, 'shellcmd') let l:command = input(g:VimuxPromptString, command, 'shellcmd')
call VimuxRunCommand(l:command) call VimuxRunCommand(l:command)
endfunction endfunction
function! s:VimuxTmux(arguments) function! s:VimuxTmux(arguments)
if s:VimuxOption('g:VimuxDebug', 0) != 0 if g:VimuxDebug
echom s:VimuxTmuxCmd().' '.a:arguments echom g:VimuxTmuxCommand.' '.a:arguments
endif endif
return system(s:VimuxTmuxCmd().' '.a:arguments) return system(g:VimuxTmuxCommand.' '.a:arguments)
endfunction endfunction
function! s:VimuxTmuxSession() function! s:VimuxTmuxSession()
@ -184,7 +184,7 @@ function! s:VimuxTmuxSession()
endfunction endfunction
function! s:VimuxTmuxIndex() function! s:VimuxTmuxIndex()
if s:VimuxRunnerType() ==# 'pane' if g:VimuxRunnerType ==# 'pane'
return s:VimuxTmuxPaneId() return s:VimuxTmuxPaneId()
else else
return s:VimuxTmuxWindowId() return s:VimuxTmuxWindowId()
@ -200,7 +200,7 @@ function! s:VimuxTmuxWindowId()
endfunction endfunction
function! s:VimuxNearestIndex() function! s:VimuxNearestIndex()
let t = s:VimuxRunnerType() let t = g:VimuxRunnerType
let filter = s:VimuxGetTargetFilter() let filter = s:VimuxGetTargetFilter()
let views = split(s:VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n') let views = split(s:VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n')
@ -214,11 +214,11 @@ function! s:VimuxNearestIndex()
endfunction endfunction
function! s:VimuxGetTargetFilter() function! s:VimuxGetTargetFilter()
let targetName = s:VimuxOption('g:VimuxRunnerName', '') let targetName = g:VimuxRunnerName
if targetName ==# '' if targetName ==# ''
return '' return ''
endif endif
let t = s:VimuxRunnerType() let t = g:VimuxRunnerType
if t ==# 'window' if t ==# 'window'
return " -f '#{==:#{window_name},".targetName."}'" return " -f '#{==:#{window_name},".targetName."}'"
elseif t ==# 'pane' elseif t ==# 'pane'
@ -227,11 +227,11 @@ function! s:VimuxGetTargetFilter()
endfunction endfunction
function! s:VimuxSetRunnerName() function! s:VimuxSetRunnerName()
let targetName = s:VimuxOption('g:VimuxRunnerName', '') let targetName = g:VimuxRunnerName
if targetName ==# '' if targetName ==# ''
return return
endif endif
let t = s:VimuxRunnerType() let t = g:VimuxRunnerType
if t ==# 'window' if t ==# 'window'
call s:VimuxTmux('rename-window '.targetName) call s:VimuxTmux('rename-window '.targetName)
elseif t ==# 'pane' elseif t ==# 'pane'
@ -239,16 +239,11 @@ function! s:VimuxSetRunnerName()
endif endif
endfunction endfunction
function! s:VimuxRunnerType()
return s:VimuxOption('g:VimuxRunnerType', 'pane')
endfunction
function! s:VimuxTmuxProperty(property) function! s:VimuxTmuxProperty(property)
return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '') return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
endfunction endfunction
function! s:VimuxHasRunner(index) function! s:VimuxHasRunner(index)
let t = s:VimuxRunnerType() let t = g:VimuxRunnerType
return match(s:VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index) return match(s:VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index)
endfunction endfunction

Loading…
Cancel
Save