From 601749152e0a504e1d8edffc74d0f094017acce7 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 16 Feb 2021 12:28:47 +0300 Subject: [PATCH 1/4] feat: Make s:VimuxOption (was _VimuxOption) public VimuxOption --- plugin/vimux.vim | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 6be8be0..83e72c6 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -3,7 +3,7 @@ if exists('g:loaded_vimux') || &compatible endif let g:loaded_vimux = 1 -function! s:VimuxOption(option, default) +function! VimuxOption(option, default) if exists(a:option) return eval(a:option) else @@ -12,7 +12,7 @@ function! s:VimuxOption(option, default) endfunction function! s:VimuxTmuxCmd() - return s:VimuxOption('g:VimuxTmuxCommand', 'tmux') + return VimuxOption('g:VimuxTmuxCommand', 'tmux') endfunction if !executable(s:VimuxTmuxCmd()) @@ -60,7 +60,7 @@ function! VimuxRunCommand(command, ...) let l:autoreturn = a:1 endif - let resetSequence = s:VimuxOption('g:VimuxResetSequence', 'q C-u') + let resetSequence = VimuxOption('g:VimuxResetSequence', 'q C-u') let g:VimuxLastCommand = a:command call VimuxSendKeys(resetSequence) @@ -86,13 +86,13 @@ endfunction function! VimuxOpenRunner() let nearestIndex = s:VimuxNearestIndex() - if s:VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1 + if VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1 let g:VimuxRunnerIndex = nearestIndex else - let extraArguments = s:VimuxOption('g:VimuxOpenExtraArgs', '') + let extraArguments = VimuxOption('g:VimuxOpenExtraArgs', '') if s:VimuxRunnerType() ==# 'pane' - let height = s:VimuxOption('g:VimuxHeight', 20) - let orientation = s:VimuxOption('g:VimuxOrientation', 'v') + let height = VimuxOption('g:VimuxHeight', 20) + let orientation = VimuxOption('g:VimuxOrientation', 'v') call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments) elseif s:VimuxRunnerType() ==# 'window' call s:VimuxTmux('new-window '.extraArguments) @@ -114,7 +114,7 @@ endfunction function! VimuxTogglePane() if exists('g:VimuxRunnerIndex') if s: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 '.VimuxOption('g:VimuxHeight', 20)) let g:VimuxRunnerType = 'pane' elseif s:VimuxRunnerType() ==# 'pane' let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '') @@ -168,12 +168,12 @@ endfunction function! VimuxPromptCommand(...) let command = a:0 ==# 1 ? a:1 : '' - let l:command = input(s:VimuxOption('g:VimuxPromptString', 'Command? '), command, 'shellcmd') + let l:command = input(VimuxOption('g:VimuxPromptString', 'Command? '), command, 'shellcmd') call VimuxRunCommand(l:command) endfunction function! s:VimuxTmux(arguments) - if s:VimuxOption('g:VimuxDebug', 0) != 0 + if VimuxOption('g:VimuxDebug', 0) != 0 echom s:VimuxTmuxCmd().' '.a:arguments endif return system(s:VimuxTmuxCmd().' '.a:arguments) @@ -214,7 +214,7 @@ function! s:VimuxNearestIndex() endfunction function! s:VimuxGetTargetFilter() - let targetName = s:VimuxOption('g:VimuxRunnerName', '') + let targetName = VimuxOption('g:VimuxRunnerName', '') if targetName ==# '' return '' endif @@ -227,7 +227,7 @@ function! s:VimuxGetTargetFilter() endfunction function! s:VimuxSetRunnerName() - let targetName = s:VimuxOption('g:VimuxRunnerName', '') + let targetName = VimuxOption('g:VimuxRunnerName', '') if targetName ==# '' return endif @@ -241,7 +241,7 @@ endfunction function! s:VimuxRunnerType() - return s:VimuxOption('g:VimuxRunnerType', 'pane') + return VimuxOption('g:VimuxRunnerType', 'pane') endfunction function! s:VimuxTmuxProperty(property) From 43681e9f91293d48bf32a107a8df445d5aac6a60 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 16 Feb 2021 12:38:31 +0300 Subject: [PATCH 2/4] refactor: Simplify script-local private function names --- plugin/vimux.vim | 112 +++++++++++++++++++++++------------------------ 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 83e72c6..0e4cac4 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -11,12 +11,12 @@ function! VimuxOption(option, default) endif endfunction -function! s:VimuxTmuxCmd() +function! s:tmuxCmd() return VimuxOption('g:VimuxTmuxCommand', 'tmux') endfunction -if !executable(s:VimuxTmuxCmd()) - echohl ErrorMsg | echomsg 'Failed to find executable '.s:VimuxTmuxCmd() | echohl None +if !executable(s:tmuxCmd()) + echohl ErrorMsg | echomsg 'Failed to find executable '.s:tmuxCmd() | echohl None finish endif @@ -51,7 +51,7 @@ function! VimuxRunLastCommand() endfunction function! VimuxRunCommand(command, ...) - if !exists('g:VimuxRunnerIndex') || s:VimuxHasRunner(g:VimuxRunnerIndex) ==# -1 + if !exists('g:VimuxRunnerIndex') || s:hasRunner(g:VimuxRunnerIndex) ==# -1 call VimuxOpenRunner() endif @@ -77,47 +77,47 @@ endfunction function! VimuxSendKeys(keys) 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 echo 'No vimux runner pane/window. Create one with VimuxOpenRunner' endif endfunction function! VimuxOpenRunner() - let nearestIndex = s:VimuxNearestIndex() + let nearestIndex = s:nearestIndex() if VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1 let g:VimuxRunnerIndex = nearestIndex else let extraArguments = VimuxOption('g:VimuxOpenExtraArgs', '') - if s:VimuxRunnerType() ==# 'pane' + if s:runnerType() ==# 'pane' let height = VimuxOption('g:VimuxHeight', 20) let orientation = VimuxOption('g:VimuxOrientation', 'v') - call s:VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments) - elseif s:VimuxRunnerType() ==# 'window' - call s:VimuxTmux('new-window '.extraArguments) + call s:tmux('split-window -p '.height.' -'.orientation.' '.extraArguments) + elseif s:runnerType() ==# 'window' + call s:tmux('new-window '.extraArguments) endif - let g:VimuxRunnerIndex = s:VimuxTmuxIndex() - call s:VimuxSetRunnerName() - call s:VimuxTmux('last-'.s:VimuxRunnerType()) + let g:VimuxRunnerIndex = s:tmuxIndex() + call s:setRunnerName() + call s:tmux('last-'.s:runnerType()) endif endfunction function! VimuxCloseRunner() 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 endif endfunction function! VimuxTogglePane() if exists('g:VimuxRunnerIndex') - if s:VimuxRunnerType() ==# 'window' - call s:VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('g:VimuxHeight', 20)) + if s:runnerType() ==# 'window' + call s:tmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('g:VimuxHeight', 20)) let g:VimuxRunnerType = 'pane' - elseif s:VimuxRunnerType() ==# 'pane' - let g:VimuxRunnerIndex=substitute(s:VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '') + elseif s:runnerType() ==# 'pane' + let g:VimuxRunnerIndex=substitute(s:tmux('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 s:VimuxRunnerType() ==# 'pane' - call s:VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex) - elseif s:VimuxRunnerType() ==# 'window' - call s:VimuxTmux('select-window -t '.g:VimuxRunnerIndex) + if s:runnerType() ==# 'pane' + call s:tmux('resize-pane -Z -t '.g:VimuxRunnerIndex) + elseif s:runnerType() ==# 'window' + call s:tmux('select-window -t '.g:VimuxRunnerIndex) endif endif endfunction function! VimuxInspectRunner() - call s:VimuxTmux('select-'.s:VimuxRunnerType().' -t '.g:VimuxRunnerIndex) - call s:VimuxTmux('copy-mode') + call s:tmux('select-'.s:runnerType().' -t '.g:VimuxRunnerIndex) + call s:tmux('copy-mode') endfunction function! VimuxScrollUpInspect() call VimuxInspectRunner() - call s:VimuxTmux('last-'.s:VimuxRunnerType()) + call s:tmux('last-'.s:runnerType()) call VimuxSendKeys('C-u') endfunction function! VimuxScrollDownInspect() call VimuxInspectRunner() - call s:VimuxTmux('last-'.s:VimuxRunnerType()) + call s:tmux('last-'.s:runnerType()) call VimuxSendKeys('C-d') endfunction @@ -162,7 +162,7 @@ endfunction function! VimuxClearRunnerHistory() if exists('g:VimuxRunnerIndex') - call s:VimuxTmux('clear-history -t '.g:VimuxRunnerIndex) + call s:tmux('clear-history -t '.g:VimuxRunnerIndex) endif endfunction @@ -172,37 +172,37 @@ function! VimuxPromptCommand(...) call VimuxRunCommand(l:command) endfunction -function! s:VimuxTmux(arguments) +function! s:tmux(arguments) if VimuxOption('g:VimuxDebug', 0) != 0 - echom s:VimuxTmuxCmd().' '.a:arguments + echom s:tmuxCmd().' '.a:arguments endif - return system(s:VimuxTmuxCmd().' '.a:arguments) + return system(s:tmuxCmd().' '.a:arguments) endfunction -function! s:VimuxTmuxSession() - return s:VimuxTmuxProperty('#S') +function! s:tmuxSession() + return s:tmuxProperty('#S') endfunction -function! s:VimuxTmuxIndex() - if s:VimuxRunnerType() ==# 'pane' - return s:VimuxTmuxPaneId() +function! s:tmuxIndex() + if s:runnerType() ==# 'pane' + return s:tmuxPaneId() else - return s:VimuxTmuxWindowId() + return s:tmuxWindowId() end endfunction -function! s:VimuxTmuxPaneId() - return s:VimuxTmuxProperty('#{pane_id}') +function! s:tmuxPaneId() + return s:tmuxProperty('#{pane_id}') endfunction -function! s:VimuxTmuxWindowId() - return s:VimuxTmuxProperty('#{window_id}') +function! s:tmuxWindowId() + return s:tmuxProperty('#{window_id}') endfunction -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') +function! s:nearestIndex() + let t = s:runnerType() + let filter = s:getTargetFilter() + let views = split(s:tmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n') for view in views if match(view, '1:') ==# -1 @@ -213,12 +213,12 @@ function! s:VimuxNearestIndex() return -1 endfunction -function! s:VimuxGetTargetFilter() +function! s:getTargetFilter() let targetName = VimuxOption('g:VimuxRunnerName', '') if targetName ==# '' return '' endif - let t = s:VimuxRunnerType() + let t = s:runnerType() if t ==# 'window' return " -f '#{==:#{window_name},".targetName."}'" elseif t ==# 'pane' @@ -226,29 +226,29 @@ function! s:VimuxGetTargetFilter() endif endfunction -function! s:VimuxSetRunnerName() +function! s:setRunnerName() let targetName = VimuxOption('g:VimuxRunnerName', '') if targetName ==# '' return endif - let t = s:VimuxRunnerType() + let t = s:runnerType() if t ==# 'window' - call s:VimuxTmux('rename-window '.targetName) + call s:tmux('rename-window '.targetName) elseif t ==# 'pane' - call s:VimuxTmux('select-pane -T '.targetName) + call s:tmux('select-pane -T '.targetName) endif endfunction -function! s:VimuxRunnerType() +function! s:runnerType() return VimuxOption('g:VimuxRunnerType', 'pane') endfunction -function! s:VimuxTmuxProperty(property) - return substitute(s:VimuxTmux("display -p '".a:property."'"), '\n$', '', '') +function! s:tmuxProperty(property) + return substitute(s:tmux("display -p '".a:property."'"), '\n$', '', '') endfunction -function! s:VimuxHasRunner(index) - let t = s:VimuxRunnerType() - return match(s:VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index) +function! s:hasRunner(index) + let t = s:runnerType() + return match(s:tmux('list-'.t."s -F '#{".t."_id}'"), a:index) endfunction From 566833e291784aaeba70f6dfcb32a9f192231420 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 16 Feb 2021 12:40:53 +0300 Subject: [PATCH 3/4] style: Format each function as a paragraph with no blanks --- plugin/vimux.vim | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index 0e4cac4..c37cb0a 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -54,18 +54,14 @@ function! VimuxRunCommand(command, ...) if !exists('g:VimuxRunnerIndex') || s:hasRunner(g:VimuxRunnerIndex) ==# -1 call VimuxOpenRunner() endif - let l:autoreturn = 1 if exists('a:1') let l:autoreturn = a:1 endif - let resetSequence = VimuxOption('g:VimuxResetSequence', 'q C-u') let g:VimuxLastCommand = a:command - call VimuxSendKeys(resetSequence) call VimuxSendText(a:command) - if l:autoreturn ==# 1 call VimuxSendKeys('Enter') endif @@ -85,7 +81,6 @@ endfunction function! VimuxOpenRunner() let nearestIndex = s:nearestIndex() - if VimuxOption('g:VimuxUseNearest', 1) ==# 1 && nearestIndex != -1 let g:VimuxRunnerIndex = nearestIndex else @@ -97,7 +92,6 @@ function! VimuxOpenRunner() elseif s:runnerType() ==# 'window' call s:tmux('new-window '.extraArguments) endif - let g:VimuxRunnerIndex = s:tmuxIndex() call s:setRunnerName() call s:tmux('last-'.s:runnerType()) @@ -203,13 +197,11 @@ function! s:nearestIndex() let t = s:runnerType() let filter = s:getTargetFilter() let views = split(s:tmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n') - for view in views if match(view, '1:') ==# -1 return split(view, ':')[1] endif endfor - return -1 endfunction @@ -229,7 +221,7 @@ endfunction function! s:setRunnerName() let targetName = VimuxOption('g:VimuxRunnerName', '') if targetName ==# '' - return + return endif let t = s:runnerType() if t ==# 'window' @@ -239,7 +231,6 @@ function! s:setRunnerName() endif endfunction - function! s:runnerType() return VimuxOption('g:VimuxRunnerType', 'pane') endfunction From 992d525ef9fa16ff4a40438b4210b0bf179edfc0 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 16 Feb 2021 13:43:24 +0300 Subject: [PATCH 4/4] feat: Make s:tmuxExec (was _VimuxTmux) public VimuxTmux --- plugin/vimux.vim | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/plugin/vimux.vim b/plugin/vimux.vim index c37cb0a..704d301 100644 --- a/plugin/vimux.vim +++ b/plugin/vimux.vim @@ -73,7 +73,7 @@ endfunction function! VimuxSendKeys(keys) if exists('g:VimuxRunnerIndex') - call s:tmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys) + call VimuxTmux('send-keys -t '.g:VimuxRunnerIndex.' '.a:keys) else echo 'No vimux runner pane/window. Create one with VimuxOpenRunner' endif @@ -88,19 +88,19 @@ function! VimuxOpenRunner() if s:runnerType() ==# 'pane' let height = VimuxOption('g:VimuxHeight', 20) let orientation = VimuxOption('g:VimuxOrientation', 'v') - call s:tmux('split-window -p '.height.' -'.orientation.' '.extraArguments) + call VimuxTmux('split-window -p '.height.' -'.orientation.' '.extraArguments) elseif s:runnerType() ==# 'window' - call s:tmux('new-window '.extraArguments) + call VimuxTmux('new-window '.extraArguments) endif let g:VimuxRunnerIndex = s:tmuxIndex() call s:setRunnerName() - call s:tmux('last-'.s:runnerType()) + call VimuxTmux('last-'.s:runnerType()) endif endfunction function! VimuxCloseRunner() if exists('g:VimuxRunnerIndex') - call s:tmux('kill-'.s:runnerType().' -t '.g:VimuxRunnerIndex) + call VimuxTmux('kill-'.s:runnerType().' -t '.g:VimuxRunnerIndex) unlet g:VimuxRunnerIndex endif endfunction @@ -108,10 +108,10 @@ endfunction function! VimuxTogglePane() if exists('g:VimuxRunnerIndex') if s:runnerType() ==# 'window' - call s:tmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('g:VimuxHeight', 20)) + call VimuxTmux('join-pane -d -s '.g:VimuxRunnerIndex.' -p '.VimuxOption('g:VimuxHeight', 20)) let g:VimuxRunnerType = 'pane' elseif s:runnerType() ==# 'pane' - let g:VimuxRunnerIndex=substitute(s:tmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '') + let g:VimuxRunnerIndex=substitute(VimuxTmux('break-pane -d -t '.g:VimuxRunnerIndex." -P -F '#{window_id}'"), '\n', '', '') let g:VimuxRunnerType = 'window' endif endif @@ -120,27 +120,27 @@ endfunction function! VimuxZoomRunner() if exists('g:VimuxRunnerIndex') if s:runnerType() ==# 'pane' - call s:tmux('resize-pane -Z -t '.g:VimuxRunnerIndex) + call VimuxTmux('resize-pane -Z -t '.g:VimuxRunnerIndex) elseif s:runnerType() ==# 'window' - call s:tmux('select-window -t '.g:VimuxRunnerIndex) + call VimuxTmux('select-window -t '.g:VimuxRunnerIndex) endif endif endfunction function! VimuxInspectRunner() - call s:tmux('select-'.s:runnerType().' -t '.g:VimuxRunnerIndex) - call s:tmux('copy-mode') + call VimuxTmux('select-'.s:runnerType().' -t '.g:VimuxRunnerIndex) + call VimuxTmux('copy-mode') endfunction function! VimuxScrollUpInspect() call VimuxInspectRunner() - call s:tmux('last-'.s:runnerType()) + call VimuxTmux('last-'.s:runnerType()) call VimuxSendKeys('C-u') endfunction function! VimuxScrollDownInspect() call VimuxInspectRunner() - call s:tmux('last-'.s:runnerType()) + call VimuxTmux('last-'.s:runnerType()) call VimuxSendKeys('C-d') endfunction @@ -156,7 +156,7 @@ endfunction function! VimuxClearRunnerHistory() if exists('g:VimuxRunnerIndex') - call s:tmux('clear-history -t '.g:VimuxRunnerIndex) + call VimuxTmux('clear-history -t '.g:VimuxRunnerIndex) endif endfunction @@ -166,7 +166,7 @@ function! VimuxPromptCommand(...) call VimuxRunCommand(l:command) endfunction -function! s:tmux(arguments) +function! VimuxTmux(arguments) if VimuxOption('g:VimuxDebug', 0) != 0 echom s:tmuxCmd().' '.a:arguments endif @@ -196,7 +196,7 @@ endfunction function! s:nearestIndex() let t = s:runnerType() let filter = s:getTargetFilter() - let views = split(s:tmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n') + let views = split(VimuxTmux('list-'.t."s -F '#{".t.'_active}:#{'.t."_id}'".filter), '\n') for view in views if match(view, '1:') ==# -1 return split(view, ':')[1] @@ -225,9 +225,9 @@ function! s:setRunnerName() endif let t = s:runnerType() if t ==# 'window' - call s:tmux('rename-window '.targetName) + call VimuxTmux('rename-window '.targetName) elseif t ==# 'pane' - call s:tmux('select-pane -T '.targetName) + call VimuxTmux('select-pane -T '.targetName) endif endfunction @@ -236,10 +236,10 @@ function! s:runnerType() endfunction function! s:tmuxProperty(property) - return substitute(s:tmux("display -p '".a:property."'"), '\n$', '', '') + return substitute(VimuxTmux("display -p '".a:property."'"), '\n$', '', '') endfunction function! s:hasRunner(index) let t = s:runnerType() - return match(s:tmux('list-'.t."s -F '#{".t."_id}'"), a:index) + return match(VimuxTmux('list-'.t."s -F '#{".t."_id}'"), a:index) endfunction