Replace underscore convention with proper script-local scopes

fix-tmux-next-3dot4
Caleb Maclennan 3 years ago
parent 925ae23b42
commit e6fb662bf1
No known key found for this signature in database
GPG Key ID: 63CC496475267693

@ -3,7 +3,7 @@ if exists("g:loaded_vimux") || &cp
endif endif
let g:loaded_vimux = 1 let g:loaded_vimux = 1
function! _VimuxOption(option, default) function! s:VimuxOption(option, default)
if exists(a:option) if exists(a:option)
return eval(a:option) return eval(a:option)
else else
@ -11,12 +11,12 @@ function! _VimuxOption(option, default)
endif endif
endfunction endfunction
function! _VimuxTmuxCmd() function! s:VimuxTmuxCmd()
return _VimuxOption("g:VimuxTmuxCommand", "tmux") return s:VimuxOption("g:VimuxTmuxCommand", "tmux")
endfunction endfunction
if !executable(_VimuxTmuxCmd()) if !executable(s:VimuxTmuxCmd())
echohl ErrorMsg | echomsg "Failed to find executable "._VimuxTmuxCmd() | echohl None echohl ErrorMsg | echomsg "Failed to find executable ".s:VimuxTmuxCmd() | echohl None
finish finish
endif endif
@ -51,7 +51,7 @@ function! VimuxRunLastCommand()
endfunction endfunction
function! VimuxRunCommand(command, ...) function! VimuxRunCommand(command, ...)
if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1 if !exists("g:VimuxRunnerIndex") || s:VimuxHasRunner(g:VimuxRunnerIndex) == -1
call VimuxOpenRunner() call VimuxOpenRunner()
endif endif
@ -60,7 +60,7 @@ function! VimuxRunCommand(command, ...)
let l:autoreturn = a:1 let l:autoreturn = a:1
endif endif
let resetSequence = _VimuxOption("g:VimuxResetSequence", "q C-u") let resetSequence = s:VimuxOption("g:VimuxResetSequence", "q C-u")
let g:VimuxLastCommand = a:command let g:VimuxLastCommand = a:command
call VimuxSendKeys(resetSequence) call VimuxSendKeys(resetSequence)
@ -77,47 +77,47 @@ endfunction
function! VimuxSendKeys(keys) function! VimuxSendKeys(keys)
if exists("g:VimuxRunnerIndex") if exists("g:VimuxRunnerIndex")
call _VimuxTmux("send-keys -t ".g:VimuxRunnerIndex." ".a:keys) call s:VimuxTmux("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 = _VimuxNearestIndex() let nearestIndex = s:VimuxNearestIndex()
if _VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1 if s:VimuxOption("g:VimuxUseNearest", 1) == 1 && nearestIndex != -1
let g:VimuxRunnerIndex = nearestIndex let g:VimuxRunnerIndex = nearestIndex
else else
let extraArguments = _VimuxOption("g:VimuxOpenExtraArgs", "") let extraArguments = s:VimuxOption("g:VimuxOpenExtraArgs", "")
if _VimuxRunnerType() == "pane" if s:VimuxRunnerType() == "pane"
let height = _VimuxOption("g:VimuxHeight", 20) let height = s:VimuxOption("g:VimuxHeight", 20)
let orientation = _VimuxOption("g:VimuxOrientation", "v") let orientation = s:VimuxOption("g:VimuxOrientation", "v")
call _VimuxTmux("split-window -p ".height." -".orientation." ".extraArguments) call s:VimuxTmux("split-window -p ".height." -".orientation." ".extraArguments)
elseif _VimuxRunnerType() == "window" elseif s:VimuxRunnerType() == "window"
call _VimuxTmux("new-window ".extraArguments) call s:VimuxTmux("new-window ".extraArguments)
endif endif
let g:VimuxRunnerIndex = _VimuxTmuxIndex() let g:VimuxRunnerIndex = s:VimuxTmuxIndex()
call _VimuxSetRunnerName() call s:VimuxSetRunnerName()
call _VimuxTmux("last-"._VimuxRunnerType()) call s:VimuxTmux("last-".s:VimuxRunnerType())
endif endif
endfunction endfunction
function! VimuxCloseRunner() function! VimuxCloseRunner()
if exists("g:VimuxRunnerIndex") if exists("g:VimuxRunnerIndex")
call _VimuxTmux("kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) call s:VimuxTmux("kill-".s: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 _VimuxRunnerType() == "window" if s:VimuxRunnerType() == "window"
call _VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p "._VimuxOption("g:VimuxHeight", 20)) call s:VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p ".s:VimuxOption("g:VimuxHeight", 20))
let g:VimuxRunnerType = "pane" let g:VimuxRunnerType = "pane"
elseif _VimuxRunnerType() == "pane" elseif s:VimuxRunnerType() == "pane"
let g:VimuxRunnerIndex=substitute(_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
endif endif
@ -125,28 +125,28 @@ endfunction
function! VimuxZoomRunner() function! VimuxZoomRunner()
if exists("g:VimuxRunnerIndex") if exists("g:VimuxRunnerIndex")
if _VimuxRunnerType() == "pane" if s:VimuxRunnerType() == "pane"
call _VimuxTmux("resize-pane -Z -t ".g:VimuxRunnerIndex) call s:VimuxTmux("resize-pane -Z -t ".g:VimuxRunnerIndex)
elseif _VimuxRunnerType() == "window" elseif s:VimuxRunnerType() == "window"
call _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 _VimuxTmux("select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) call s:VimuxTmux("select-".s:VimuxRunnerType()." -t ".g:VimuxRunnerIndex)
call _VimuxTmux("copy-mode") call s:VimuxTmux("copy-mode")
endfunction endfunction
function! VimuxScrollUpInspect() function! VimuxScrollUpInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call _VimuxTmux("last-"._VimuxRunnerType()) call s:VimuxTmux("last-".s:VimuxRunnerType())
call VimuxSendKeys("C-u") call VimuxSendKeys("C-u")
endfunction endfunction
function! VimuxScrollDownInspect() function! VimuxScrollDownInspect()
call VimuxInspectRunner() call VimuxInspectRunner()
call _VimuxTmux("last-"._VimuxRunnerType()) call s:VimuxTmux("last-".s:VimuxRunnerType())
call VimuxSendKeys("C-d") call VimuxSendKeys("C-d")
endfunction endfunction
@ -162,47 +162,47 @@ endfunction
function! VimuxClearRunnerHistory() function! VimuxClearRunnerHistory()
if exists("g:VimuxRunnerIndex") if exists("g:VimuxRunnerIndex")
call _VimuxTmux("clear-history -t ".g:VimuxRunnerIndex) call s:VimuxTmux("clear-history -t ".g:VimuxRunnerIndex)
endif endif
endfunction endfunction
function! VimuxPromptCommand(...) function! VimuxPromptCommand(...)
let command = a:0 == 1 ? a:1 : "" let command = a:0 == 1 ? a:1 : ""
let l:command = input(_VimuxOption("g:VimuxPromptString", "Command? "), command, 'shellcmd') let l:command = input(s:VimuxOption("g:VimuxPromptString", "Command? "), command, 'shellcmd')
call VimuxRunCommand(l:command) call VimuxRunCommand(l:command)
endfunction endfunction
function! _VimuxTmux(arguments) function! s:VimuxTmux(arguments)
if _VimuxOption("g:VimuxDebug", 0) != 0 if s:VimuxOption("g:VimuxDebug", 0) != 0
echom _VimuxTmuxCmd()." ".a:arguments echom s:VimuxTmuxCmd()." ".a:arguments
endif endif
return system(_VimuxTmuxCmd()." ".a:arguments) return system(s:VimuxTmuxCmd()." ".a:arguments)
endfunction endfunction
function! _VimuxTmuxSession() function! s:VimuxTmuxSession()
return _VimuxTmuxProperty("#S") return s:VimuxTmuxProperty("#S")
endfunction endfunction
function! _VimuxTmuxIndex() function! s:VimuxTmuxIndex()
if _VimuxRunnerType() == "pane" if s:VimuxRunnerType() == "pane"
return _VimuxTmuxPaneId() return s:VimuxTmuxPaneId()
else else
return _VimuxTmuxWindowId() return s:VimuxTmuxWindowId()
end end
endfunction endfunction
function! _VimuxTmuxPaneId() function! s:VimuxTmuxPaneId()
return _VimuxTmuxProperty("#{pane_id}") return s:VimuxTmuxProperty("#{pane_id}")
endfunction endfunction
function! _VimuxTmuxWindowId() function! s:VimuxTmuxWindowId()
return _VimuxTmuxProperty("#{window_id}") return s:VimuxTmuxProperty("#{window_id}")
endfunction endfunction
function! _VimuxNearestIndex() function! s:VimuxNearestIndex()
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
let filter = _VimuxGetTargetFilter() let filter = s:VimuxGetTargetFilter()
let views = split(_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")
for view in views for view in views
if match(view, "1:") == -1 if match(view, "1:") == -1
@ -213,12 +213,12 @@ function! _VimuxNearestIndex()
return -1 return -1
endfunction endfunction
function! _VimuxGetTargetFilter() function! s:VimuxGetTargetFilter()
let targetName = _VimuxOption("g:VimuxRunnerName", "") let targetName = s:VimuxOption("g:VimuxRunnerName", "")
if targetName == "" if targetName == ""
return "" return ""
endif endif
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
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! _VimuxGetTargetFilter()
endif endif
endfunction endfunction
function! _VimuxSetRunnerName() function! s:VimuxSetRunnerName()
let targetName = _VimuxOption("g:VimuxRunnerName", "") let targetName = s:VimuxOption("g:VimuxRunnerName", "")
if targetName == "" if targetName == ""
return return
endif endif
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
if t == "window" if t == "window"
call _VimuxTmux("rename-window ".targetName) call s:VimuxTmux("rename-window ".targetName)
elseif t == "pane" elseif t == "pane"
call _VimuxTmux("select-pane -T ".targetName) call s:VimuxTmux("select-pane -T ".targetName)
endif endif
endfunction endfunction
function! _VimuxRunnerType() function! s:VimuxRunnerType()
return _VimuxOption("g:VimuxRunnerType", "pane") return s:VimuxOption("g:VimuxRunnerType", "pane")
endfunction endfunction
function! _VimuxTmuxProperty(property) function! s:VimuxTmuxProperty(property)
return substitute(_VimuxTmux("display -p '".a:property."'"), '\n$', '', '') return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '')
endfunction endfunction
function! _VimuxHasRunner(index) function! s:VimuxHasRunner(index)
let t = _VimuxRunnerType() let t = s:VimuxRunnerType()
return match(_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