From e6fb662bf1645d0befe753b575b3c2bb2c1e86e2 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sun, 14 Feb 2021 16:50:14 +0300 Subject: [PATCH] Replace underscore convention with proper script-local scopes --- plugin/vimux.vim | 136 +++++++++++++++++++++++------------------------ 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 7b8d4ce..a68ccec 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -3,7 +3,7 @@ if exists("g:loaded_vimux") || &cp endif let g:loaded_vimux = 1 -function! _VimuxOption(option, default) +function! s:VimuxOption(option, default) if exists(a:option) return eval(a:option) else @@ -11,12 +11,12 @@ function! _VimuxOption(option, default) endif endfunction -function! _VimuxTmuxCmd() - return _VimuxOption("g:VimuxTmuxCommand", "tmux") +function! s:VimuxTmuxCmd() + return s:VimuxOption("g:VimuxTmuxCommand", "tmux") endfunction -if !executable(_VimuxTmuxCmd()) - echohl ErrorMsg | echomsg "Failed to find executable "._VimuxTmuxCmd() | echohl None +if !executable(s:VimuxTmuxCmd()) + echohl ErrorMsg | echomsg "Failed to find executable ".s:VimuxTmuxCmd() | echohl None finish endif @@ -51,7 +51,7 @@ function! VimuxRunLastCommand() endfunction function! VimuxRunCommand(command, ...) - if !exists("g:VimuxRunnerIndex") || _VimuxHasRunner(g:VimuxRunnerIndex) == -1 + if !exists("g:VimuxRunnerIndex") || s:VimuxHasRunner(g:VimuxRunnerIndex) == -1 call VimuxOpenRunner() endif @@ -60,7 +60,7 @@ function! VimuxRunCommand(command, ...) let l:autoreturn = a:1 endif - let resetSequence = _VimuxOption("g:VimuxResetSequence", "q C-u") + let resetSequence = s:VimuxOption("g:VimuxResetSequence", "q C-u") let g:VimuxLastCommand = a:command call VimuxSendKeys(resetSequence) @@ -77,47 +77,47 @@ endfunction function! VimuxSendKeys(keys) if exists("g:VimuxRunnerIndex") - call _VimuxTmux("send-keys -t ".g:VimuxRunnerIndex." ".a:keys) + call s:VimuxTmux("send-keys -t ".g:VimuxRunnerIndex." ".a:keys) else echo "No vimux runner pane/window. Create one with VimuxOpenRunner" endif endfunction 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 else - let extraArguments = _VimuxOption("g:VimuxOpenExtraArgs", "") - if _VimuxRunnerType() == "pane" - let height = _VimuxOption("g:VimuxHeight", 20) - let orientation = _VimuxOption("g:VimuxOrientation", "v") - call _VimuxTmux("split-window -p ".height." -".orientation." ".extraArguments) - elseif _VimuxRunnerType() == "window" - call _VimuxTmux("new-window ".extraArguments) + let extraArguments = s:VimuxOption("g:VimuxOpenExtraArgs", "") + if s:VimuxRunnerType() == "pane" + let height = s:VimuxOption("g:VimuxHeight", 20) + let orientation = s:VimuxOption("g:VimuxOrientation", "v") + call s:VimuxTmux("split-window -p ".height." -".orientation." ".extraArguments) + elseif s:VimuxRunnerType() == "window" + call s:VimuxTmux("new-window ".extraArguments) endif - let g:VimuxRunnerIndex = _VimuxTmuxIndex() - call _VimuxSetRunnerName() - call _VimuxTmux("last-"._VimuxRunnerType()) + let g:VimuxRunnerIndex = s:VimuxTmuxIndex() + call s:VimuxSetRunnerName() + call s:VimuxTmux("last-".s:VimuxRunnerType()) endif endfunction function! VimuxCloseRunner() if exists("g:VimuxRunnerIndex") - call _VimuxTmux("kill-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) + call s:VimuxTmux("kill-".s:VimuxRunnerType()." -t ".g:VimuxRunnerIndex) unlet g:VimuxRunnerIndex endif endfunction function! VimuxTogglePane() if exists("g:VimuxRunnerIndex") - if _VimuxRunnerType() == "window" - call _VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p "._VimuxOption("g:VimuxHeight", 20)) + if s:VimuxRunnerType() == "window" + call s:VimuxTmux("join-pane -d -s ".g:VimuxRunnerIndex." -p ".s:VimuxOption("g:VimuxHeight", 20)) let g:VimuxRunnerType = "pane" - elseif _VimuxRunnerType() == "pane" - let g:VimuxRunnerIndex=substitute(_VimuxTmux("break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_id}'"), "\n", "", "") + elseif s:VimuxRunnerType() == "pane" + let g:VimuxRunnerIndex=substitute(s:VimuxTmux("break-pane -d -t ".g:VimuxRunnerIndex." -P -F '#{window_id}'"), "\n", "", "") let g:VimuxRunnerType = "window" endif endif @@ -125,28 +125,28 @@ endfunction function! VimuxZoomRunner() if exists("g:VimuxRunnerIndex") - if _VimuxRunnerType() == "pane" - call _VimuxTmux("resize-pane -Z -t ".g:VimuxRunnerIndex) - elseif _VimuxRunnerType() == "window" - call _VimuxTmux("select-window -t ".g:VimuxRunnerIndex) + if s:VimuxRunnerType() == "pane" + call s:VimuxTmux("resize-pane -Z -t ".g:VimuxRunnerIndex) + elseif s:VimuxRunnerType() == "window" + call s:VimuxTmux("select-window -t ".g:VimuxRunnerIndex) endif endif endfunction function! VimuxInspectRunner() - call _VimuxTmux("select-"._VimuxRunnerType()." -t ".g:VimuxRunnerIndex) - call _VimuxTmux("copy-mode") + call s:VimuxTmux("select-".s:VimuxRunnerType()." -t ".g:VimuxRunnerIndex) + call s:VimuxTmux("copy-mode") endfunction function! VimuxScrollUpInspect() call VimuxInspectRunner() - call _VimuxTmux("last-"._VimuxRunnerType()) + call s:VimuxTmux("last-".s:VimuxRunnerType()) call VimuxSendKeys("C-u") endfunction function! VimuxScrollDownInspect() call VimuxInspectRunner() - call _VimuxTmux("last-"._VimuxRunnerType()) + call s:VimuxTmux("last-".s:VimuxRunnerType()) call VimuxSendKeys("C-d") endfunction @@ -162,47 +162,47 @@ endfunction function! VimuxClearRunnerHistory() if exists("g:VimuxRunnerIndex") - call _VimuxTmux("clear-history -t ".g:VimuxRunnerIndex) + call s:VimuxTmux("clear-history -t ".g:VimuxRunnerIndex) endif endfunction function! VimuxPromptCommand(...) 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) endfunction -function! _VimuxTmux(arguments) - if _VimuxOption("g:VimuxDebug", 0) != 0 - echom _VimuxTmuxCmd()." ".a:arguments +function! s:VimuxTmux(arguments) + if s:VimuxOption("g:VimuxDebug", 0) != 0 + echom s:VimuxTmuxCmd()." ".a:arguments endif - return system(_VimuxTmuxCmd()." ".a:arguments) + return system(s:VimuxTmuxCmd()." ".a:arguments) endfunction -function! _VimuxTmuxSession() - return _VimuxTmuxProperty("#S") +function! s:VimuxTmuxSession() + return s:VimuxTmuxProperty("#S") endfunction -function! _VimuxTmuxIndex() - if _VimuxRunnerType() == "pane" - return _VimuxTmuxPaneId() +function! s:VimuxTmuxIndex() + if s:VimuxRunnerType() == "pane" + return s:VimuxTmuxPaneId() else - return _VimuxTmuxWindowId() + return s:VimuxTmuxWindowId() end endfunction -function! _VimuxTmuxPaneId() - return _VimuxTmuxProperty("#{pane_id}") +function! s:VimuxTmuxPaneId() + return s:VimuxTmuxProperty("#{pane_id}") endfunction -function! _VimuxTmuxWindowId() - return _VimuxTmuxProperty("#{window_id}") +function! s:VimuxTmuxWindowId() + return s:VimuxTmuxProperty("#{window_id}") endfunction -function! _VimuxNearestIndex() - let t = _VimuxRunnerType() - let filter = _VimuxGetTargetFilter() - let views = split(_VimuxTmux("list-".t."s -F '#{".t."_active}:#{".t."_id}'".filter), "\n") +function! s:VimuxNearestIndex() + let t = s:VimuxRunnerType() + let filter = s:VimuxGetTargetFilter() + let views = split(s:VimuxTmux("list-".t."s -F '#{".t."_active}:#{".t."_id}'".filter), "\n") for view in views if match(view, "1:") == -1 @@ -213,12 +213,12 @@ function! _VimuxNearestIndex() return -1 endfunction -function! _VimuxGetTargetFilter() - let targetName = _VimuxOption("g:VimuxRunnerName", "") +function! s:VimuxGetTargetFilter() + let targetName = s:VimuxOption("g:VimuxRunnerName", "") if targetName == "" return "" endif - let t = _VimuxRunnerType() + let t = s:VimuxRunnerType() if t == "window" return " -f '#{==:#{window_name},".targetName."}'" elseif t == "pane" @@ -226,29 +226,29 @@ function! _VimuxGetTargetFilter() endif endfunction -function! _VimuxSetRunnerName() - let targetName = _VimuxOption("g:VimuxRunnerName", "") +function! s:VimuxSetRunnerName() + let targetName = s:VimuxOption("g:VimuxRunnerName", "") if targetName == "" return endif - let t = _VimuxRunnerType() + let t = s:VimuxRunnerType() if t == "window" - call _VimuxTmux("rename-window ".targetName) + call s:VimuxTmux("rename-window ".targetName) elseif t == "pane" - call _VimuxTmux("select-pane -T ".targetName) + call s:VimuxTmux("select-pane -T ".targetName) endif endfunction -function! _VimuxRunnerType() - return _VimuxOption("g:VimuxRunnerType", "pane") +function! s:VimuxRunnerType() + return s:VimuxOption("g:VimuxRunnerType", "pane") endfunction -function! _VimuxTmuxProperty(property) - return substitute(_VimuxTmux("display -p '".a:property."'"), '\n$', '', '') +function! s:VimuxTmuxProperty(property) + return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '') endfunction -function! _VimuxHasRunner(index) - let t = _VimuxRunnerType() - return match(_VimuxTmux("list-".t."s -F '#{".t."_id}'"), a:index) +function! s:VimuxHasRunner(index) + let t = s:VimuxRunnerType() + return match(s:VimuxTmux("list-".t."s -F '#{".t."_id}'"), a:index) endfunction