@@ -3,20 +3,20 @@ if exists('g:loaded_vimux') || &compatible
3
3
endif
4
4
let g: loaded_vimux = 1
5
5
6
- function ! s: VimuxOption (option , default)
6
+ function ! VimuxOption (option , default)
7
7
if exists (a: option )
8
8
return eval (a: option )
9
9
else
10
10
return a: default
11
11
endif
12
12
endfunction
13
13
14
- function ! s: VimuxTmuxCmd ()
15
- return s: VimuxOption (' g:VimuxTmuxCommand' , ' tmux' )
14
+ function ! s: tmuxCmd ()
15
+ return VimuxOption (' g:VimuxTmuxCommand' , ' tmux' )
16
16
endfunction
17
17
18
- if ! executable (s: VimuxTmuxCmd ())
19
- echohl ErrorMsg | echomsg ' Failed to find executable ' .s: VimuxTmuxCmd () | echohl None
18
+ if ! executable (s: tmuxCmd ())
19
+ echohl ErrorMsg | echomsg ' Failed to find executable ' .s: tmuxCmd () | echohl None
20
20
finish
21
21
endif
22
22
@@ -51,21 +51,17 @@ function! VimuxRunLastCommand()
51
51
endfunction
52
52
53
53
function ! VimuxRunCommand (command , ... )
54
- if ! exists (' g:VimuxRunnerIndex' ) || s: VimuxHasRunner (g: VimuxRunnerIndex ) == # -1
54
+ if ! exists (' g:VimuxRunnerIndex' ) || s: hasRunner (g: VimuxRunnerIndex ) == # -1
55
55
call VimuxOpenRunner ()
56
56
endif
57
-
58
57
let l: autoreturn = 1
59
58
if exists (' a:1' )
60
59
let l: autoreturn = a: 1
61
60
endif
62
-
63
- let resetSequence = s: VimuxOption (' g:VimuxResetSequence' , ' q C-u' )
61
+ let resetSequence = VimuxOption (' g:VimuxResetSequence' , ' q C-u' )
64
62
let g: VimuxLastCommand = a: command
65
-
66
63
call VimuxSendKeys (resetSequence)
67
64
call VimuxSendText (a: command )
68
-
69
65
if l: autoreturn == # 1
70
66
call VimuxSendKeys (' Enter' )
71
67
endif
@@ -77,76 +73,74 @@ endfunction
77
73
78
74
function ! VimuxSendKeys (keys )
79
75
if exists (' g:VimuxRunnerIndex' )
80
- call s: VimuxTmux (' send-keys -t ' .g: VimuxRunnerIndex .' ' .a: keys )
76
+ call VimuxTmux (' send-keys -t ' .g: VimuxRunnerIndex .' ' .a: keys )
81
77
else
82
78
echo ' No vimux runner pane/window. Create one with VimuxOpenRunner'
83
79
endif
84
80
endfunction
85
81
86
82
function ! VimuxOpenRunner ()
87
- let nearestIndex = s: VimuxNearestIndex ()
88
-
89
- if s: VimuxOption (' g:VimuxUseNearest' , 1 ) == # 1 && nearestIndex != -1
83
+ let nearestIndex = s: nearestIndex ()
84
+ if VimuxOption (' g:VimuxUseNearest' , 1 ) == # 1 && nearestIndex != -1
90
85
let g: VimuxRunnerIndex = nearestIndex
91
86
else
92
- let extraArguments = s: VimuxOption (' g:VimuxOpenExtraArgs' , ' ' )
93
- if s: VimuxRunnerType () == # ' pane'
94
- let height = s: VimuxOption (' g:VimuxHeight' , 20 )
95
- let orientation = s: VimuxOption (' g:VimuxOrientation' , ' v' )
96
- call s: VimuxTmux (' split-window -p ' .height.' -' .orientation.' ' .extraArguments)
97
- elseif s: VimuxRunnerType () == # ' window'
98
- call s: VimuxTmux (' new-window ' .extraArguments)
87
+ let extraArguments = VimuxOption (' g:VimuxOpenExtraArgs' , ' ' )
88
+ if s: runnerType () == # ' pane'
89
+ let height = VimuxOption (' g:VimuxHeight' , 20 )
90
+ let orientation = VimuxOption (' g:VimuxOrientation' , ' v' )
91
+ call VimuxTmux (' split-window -p ' .height.' -' .orientation.' ' .extraArguments)
92
+ elseif s: runnerType () == # ' window'
93
+ call VimuxTmux (' new-window ' .extraArguments)
99
94
endif
100
-
101
- let g: VimuxRunnerIndex = s: VimuxTmuxIndex ()
102
- call s: VimuxSetRunnerName ()
103
- call s: VimuxTmux (' last-' .s: VimuxRunnerType ())
95
+ let g: VimuxRunnerIndex = s: tmuxIndex ()
96
+ call s: setRunnerName ()
97
+ call VimuxTmux (' last-' .s: runnerType ())
104
98
endif
105
99
endfunction
106
100
107
101
function ! VimuxCloseRunner ()
108
102
if exists (' g:VimuxRunnerIndex' )
109
- call s: VimuxTmux (' kill-' .s: VimuxRunnerType ().' -t ' .g: VimuxRunnerIndex )
103
+ call VimuxTmux (' kill-' .s: runnerType ().' -t ' .g: VimuxRunnerIndex )
110
104
unlet g: VimuxRunnerIndex
111
105
endif
112
106
endfunction
113
107
114
108
function ! VimuxTogglePane ()
115
109
if exists (' g:VimuxRunnerIndex' )
116
- if s: VimuxRunnerType () == # ' window'
117
- call s: VimuxTmux (' join-pane -d -s ' .g: VimuxRunnerIndex .' -p ' .s: VimuxOption (' g:VimuxHeight' , 20 ))
110
+ if s: runnerType () == # ' window'
111
+ call VimuxTmux (' join-pane -d -s ' .g: VimuxRunnerIndex .' -p ' .VimuxOption (' g:VimuxHeight' , 20 ))
118
112
let g: VimuxRunnerType = ' pane'
119
- elseif s: VimuxRunnerType () == # ' pane'
120
- let g: VimuxRunnerIndex= substitute (s: VimuxTmux (' break-pane -d -t ' .g: VimuxRunnerIndex ." -P -F '#{window_id}'" ), ' \n' , ' ' , ' ' )
113
+ elseif s: runnerType () == # ' pane'
114
+ let g: VimuxRunnerIndex= substitute (VimuxTmux (' break-pane -d -t ' .g: VimuxRunnerIndex ." -P -F '#{window_id}'" ), ' \n' , ' ' , ' ' )
121
115
let g: VimuxRunnerType = ' window'
122
116
endif
123
117
endif
124
118
endfunction
125
119
126
120
function ! VimuxZoomRunner ()
127
121
if exists (' g:VimuxRunnerIndex' )
128
- if s: VimuxRunnerType () == # ' pane'
129
- call s: VimuxTmux (' resize-pane -Z -t ' .g: VimuxRunnerIndex )
130
- elseif s: VimuxRunnerType () == # ' window'
131
- call s: VimuxTmux (' select-window -t ' .g: VimuxRunnerIndex )
122
+ if s: runnerType () == # ' pane'
123
+ call VimuxTmux (' resize-pane -Z -t ' .g: VimuxRunnerIndex )
124
+ elseif s: runnerType () == # ' window'
125
+ call VimuxTmux (' select-window -t ' .g: VimuxRunnerIndex )
132
126
endif
133
127
endif
134
128
endfunction
135
129
136
130
function ! VimuxInspectRunner ()
137
- call s: VimuxTmux (' select-' .s: VimuxRunnerType ().' -t ' .g: VimuxRunnerIndex )
138
- call s: VimuxTmux (' copy-mode' )
131
+ call VimuxTmux (' select-' .s: runnerType ().' -t ' .g: VimuxRunnerIndex )
132
+ call VimuxTmux (' copy-mode' )
139
133
endfunction
140
134
141
135
function ! VimuxScrollUpInspect ()
142
136
call VimuxInspectRunner ()
143
- call s: VimuxTmux (' last-' .s: VimuxRunnerType ())
137
+ call VimuxTmux (' last-' .s: runnerType ())
144
138
call VimuxSendKeys (' C-u' )
145
139
endfunction
146
140
147
141
function ! VimuxScrollDownInspect ()
148
142
call VimuxInspectRunner ()
149
- call s: VimuxTmux (' last-' .s: VimuxRunnerType ())
143
+ call VimuxTmux (' last-' .s: runnerType ())
150
144
call VimuxSendKeys (' C-d' )
151
145
endfunction
152
146
@@ -162,93 +156,90 @@ endfunction
162
156
163
157
function ! VimuxClearRunnerHistory ()
164
158
if exists (' g:VimuxRunnerIndex' )
165
- call s: VimuxTmux (' clear-history -t ' .g: VimuxRunnerIndex )
159
+ call VimuxTmux (' clear-history -t ' .g: VimuxRunnerIndex )
166
160
endif
167
161
endfunction
168
162
169
163
function ! VimuxPromptCommand (... )
170
164
let command = a: 0 == # 1 ? a: 1 : ' '
171
- let l: command = input (s: VimuxOption (' g:VimuxPromptString' , ' Command? ' ), command , ' shellcmd' )
165
+ let l: command = input (VimuxOption (' g:VimuxPromptString' , ' Command? ' ), command , ' shellcmd' )
172
166
call VimuxRunCommand (l: command )
173
167
endfunction
174
168
175
- function ! s: VimuxTmux (arguments)
176
- if s: VimuxOption (' g:VimuxDebug' , 0 ) != 0
177
- echom s: VimuxTmuxCmd ().' ' .a: arguments
169
+ function ! VimuxTmux (arguments)
170
+ if VimuxOption (' g:VimuxDebug' , 0 ) != 0
171
+ echom s: tmuxCmd ().' ' .a: arguments
178
172
endif
179
- return system (s: VimuxTmuxCmd ().' ' .a: arguments )
173
+ return system (s: tmuxCmd ().' ' .a: arguments )
180
174
endfunction
181
175
182
- function ! s: VimuxTmuxSession ()
183
- return s: VimuxTmuxProperty (' #S' )
176
+ function ! s: tmuxSession ()
177
+ return s: tmuxProperty (' #S' )
184
178
endfunction
185
179
186
- function ! s: VimuxTmuxIndex ()
187
- if s: VimuxRunnerType () == # ' pane'
188
- return s: VimuxTmuxPaneId ()
180
+ function ! s: tmuxIndex ()
181
+ if s: runnerType () == # ' pane'
182
+ return s: tmuxPaneId ()
189
183
else
190
- return s: VimuxTmuxWindowId ()
184
+ return s: tmuxWindowId ()
191
185
end
192
186
endfunction
193
187
194
- function ! s: VimuxTmuxPaneId ()
195
- return s: VimuxTmuxProperty (' #{pane_id}' )
188
+ function ! s: tmuxPaneId ()
189
+ return s: tmuxProperty (' #{pane_id}' )
196
190
endfunction
197
191
198
- function ! s: VimuxTmuxWindowId ()
199
- return s: VimuxTmuxProperty (' #{window_id}' )
192
+ function ! s: tmuxWindowId ()
193
+ return s: tmuxProperty (' #{window_id}' )
200
194
endfunction
201
195
202
- function ! s: VimuxNearestIndex ()
203
- let t = s: VimuxRunnerType ()
204
- let filter = s: VimuxGetTargetFilter ()
205
- let views = split (s: VimuxTmux (' list-' .t ." s -F '#{" .t .' _active}:#{' .t ." _id}'" .filter ), ' \n' )
206
-
196
+ function ! s: nearestIndex ()
197
+ let t = s: runnerType ()
198
+ let filter = s: getTargetFilter ()
199
+ let views = split (VimuxTmux (' list-' .t ." s -F '#{" .t .' _active}:#{' .t ." _id}'" .filter ), ' \n' )
207
200
for view in views
208
201
if match (view , ' 1:' ) == # -1
209
202
return split (view , ' :' )[1 ]
210
203
endif
211
204
endfor
212
-
213
205
return -1
214
206
endfunction
215
207
216
- function ! s: VimuxGetTargetFilter ()
217
- let targetName = s: VimuxOption (' g:VimuxRunnerName' , ' ' )
208
+ function ! s: getTargetFilter ()
209
+ let targetName = VimuxOption (' g:VimuxRunnerName' , ' ' )
218
210
if targetName == # ' '
219
211
return ' '
220
212
endif
221
- let t = s: VimuxRunnerType ()
213
+ let t = s: runnerType ()
222
214
if t == # ' window'
223
215
return " -f '#{==:#{window_name}," .targetName." }'"
224
216
elseif t == # ' pane'
225
217
return " -f '#{==:#{pane_title}," .targetName." }'"
226
218
endif
227
219
endfunction
228
220
229
- function ! s: VimuxSetRunnerName ()
230
- let targetName = s: VimuxOption (' g:VimuxRunnerName' , ' ' )
221
+ function ! s: setRunnerName ()
222
+ let targetName = VimuxOption (' g:VimuxRunnerName' , ' ' )
231
223
if targetName == # ' '
232
- return
224
+ return
233
225
endif
234
- let t = s: VimuxRunnerType ()
226
+ let t = s: runnerType ()
235
227
if t == # ' window'
236
- call s: VimuxTmux (' rename-window ' .targetName)
228
+ call VimuxTmux (' rename-window ' .targetName)
237
229
elseif t == # ' pane'
238
- call s: VimuxTmux (' select-pane -T ' .targetName)
230
+ call VimuxTmux (' select-pane -T ' .targetName)
239
231
endif
240
232
endfunction
241
233
242
-
243
- function ! s: VimuxRunnerType ()
244
- return s: VimuxOption (' g:VimuxRunnerType' , ' pane' )
234
+ function ! s: runnerType ()
235
+ return VimuxOption (' g:VimuxRunnerType' , ' pane' )
245
236
endfunction
246
237
247
- function ! s: VimuxTmuxProperty (property)
248
- return substitute (s: VimuxTmux (" display -p '" .a: property ." '" ), ' \n$' , ' ' , ' ' )
238
+ function ! s: tmuxProperty (property)
239
+ return substitute (VimuxTmux (" display -p '" .a: property ." '" ), ' \n$' , ' ' , ' ' )
249
240
endfunction
250
241
251
- function ! s: VimuxHasRunner (index )
252
- let t = s: VimuxRunnerType ()
253
- return match (s: VimuxTmux (' list-' .t ." s -F '#{" .t ." _id}'" ), a: index )
242
+ function ! s: hasRunner (index )
243
+ let t = s: runnerType ()
244
+ return match (VimuxTmux (' list-' .t ." s -F '#{" .t ." _id}'" ), a: index )
254
245
endfunction
0 commit comments