@@ -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)
7
- if exists ( a: option )
8
- return eval ( a: option )
9
- else
10
- return a: default
11
- endif
12
- endfunction
13
-
14
- function ! s: VimuxTmuxCmd ( )
15
- return s: VimuxOption ( ' g: VimuxTmuxCommand' , ' tmux' )
16
- endfunction
17
-
18
- if ! executable (s: VimuxTmuxCmd () )
19
- echohl ErrorMsg | echomsg ' Failed to find executable ' .s: VimuxTmuxCmd () | echohl None
6
+ " Set up all global options with defaults right away, in one place
7
+ let g: VimuxDebug = get ( g: , ' VimuxDebug ' , v: false )
8
+ let g: VimuxHeight = get ( g: , ' VimuxHeight ' , 20 )
9
+ let g: VimuxOpenExtraArgs = get ( g: , ' VimuxOpenExtraArgs ' , ' ' )
10
+ let g: VimuxOrientation = get ( g: , ' VimuxOrientation ' , ' v ' )
11
+ let g: VimuxPromptString = get ( g: , ' VimuxPromptString ' , ' Command? ' )
12
+ let g: VimuxResetSequence = get ( g: , ' VimuxResetSequence ' , ' q C-u ' )
13
+ let g: VimuxRunnerName = get ( g: , ' VimuxRunnerName ' , ' ' )
14
+ let g: VimuxRunnerType = get ( g: , ' VimuxRunnerType ' , ' pane ' )
15
+ let g: VimuxTmuxCommand = get ( g: , ' VimuxTmuxCommand' , ' tmux' )
16
+ let g: VimuxUseNearest = get ( g: , ' VimuxUseNearest ' , v: true )
17
+
18
+ if ! executable (g: VimuxTmuxCommand )
19
+ echohl ErrorMsg | echomsg ' Failed to find executable ' .g: VimuxTmuxCommand | echohl None
20
20
finish
21
21
endif
22
22
@@ -60,7 +60,7 @@ function! VimuxRunCommand(command, ...)
60
60
let l: autoreturn = a: 1
61
61
endif
62
62
63
- let resetSequence = s: VimuxOption ( ' g:VimuxResetSequence' , ' q C-u ' )
63
+ let resetSequence = g: VimuxResetSequence
64
64
let g: VimuxLastCommand = a: command
65
65
66
66
call VimuxSendKeys (resetSequence)
@@ -86,37 +86,37 @@ endfunction
86
86
function ! VimuxOpenRunner ()
87
87
let nearestIndex = s: VimuxNearestIndex ()
88
88
89
- if s: VimuxOption ( ' g:VimuxUseNearest' , 1 ) == # 1 && nearestIndex != -1
89
+ if g: VimuxUseNearest == # 1 && nearestIndex != -1
90
90
let g: VimuxRunnerIndex = nearestIndex
91
91
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 ' )
92
+ let extraArguments = g: VimuxOpenExtraArgs
93
+ if g : VimuxRunnerType == # ' pane'
94
+ let height = g: VimuxHeight
95
+ let orientation = g: VimuxOrientation
96
96
call s: VimuxTmux (' split-window -p ' .height.' -' .orientation.' ' .extraArguments)
97
- elseif s : VimuxRunnerType() == # ' window'
97
+ elseif g : VimuxRunnerType == # ' window'
98
98
call s: VimuxTmux (' new-window ' .extraArguments)
99
99
endif
100
100
101
101
let g: VimuxRunnerIndex = s: VimuxTmuxIndex ()
102
102
call s: VimuxSetRunnerName ()
103
- call s: VimuxTmux (' last-' .s : VimuxRunnerType() )
103
+ call s: VimuxTmux (' last-' .g : VimuxRunnerType )
104
104
endif
105
105
endfunction
106
106
107
107
function ! VimuxCloseRunner ()
108
108
if exists (' g:VimuxRunnerIndex' )
109
- call s: VimuxTmux (' kill-' .s : VimuxRunnerType() .' -t ' .g: VimuxRunnerIndex )
109
+ call s: VimuxTmux (' kill-' .g : VimuxRunnerType .' -t ' .g: VimuxRunnerIndex )
110
110
unlet g: VimuxRunnerIndex
111
111
endif
112
112
endfunction
113
113
114
114
function ! VimuxTogglePane ()
115
115
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 ) )
116
+ if g : VimuxRunnerType == # ' window'
117
+ call s: VimuxTmux (' join-pane -d -s ' .g: VimuxRunnerIndex .' -p ' .g: VimuxHeight )
118
118
let g: VimuxRunnerType = ' pane'
119
- elseif s : VimuxRunnerType() == # ' pane'
119
+ elseif g : VimuxRunnerType == # ' pane'
120
120
let g: VimuxRunnerIndex= substitute (s: VimuxTmux (' break-pane -d -t ' .g: VimuxRunnerIndex ." -P -F '#{window_id}'" ), ' \n' , ' ' , ' ' )
121
121
let g: VimuxRunnerType = ' window'
122
122
endif
@@ -125,28 +125,28 @@ endfunction
125
125
126
126
function ! VimuxZoomRunner ()
127
127
if exists (' g:VimuxRunnerIndex' )
128
- if s : VimuxRunnerType() == # ' pane'
128
+ if g : VimuxRunnerType == # ' pane'
129
129
call s: VimuxTmux (' resize-pane -Z -t ' .g: VimuxRunnerIndex )
130
- elseif s : VimuxRunnerType() == # ' window'
130
+ elseif g : VimuxRunnerType == # ' window'
131
131
call s: VimuxTmux (' select-window -t ' .g: VimuxRunnerIndex )
132
132
endif
133
133
endif
134
134
endfunction
135
135
136
136
function ! VimuxInspectRunner ()
137
- call s: VimuxTmux (' select-' .s : VimuxRunnerType() .' -t ' .g: VimuxRunnerIndex )
137
+ call s: VimuxTmux (' select-' .g : VimuxRunnerType .' -t ' .g: VimuxRunnerIndex )
138
138
call s: VimuxTmux (' copy-mode' )
139
139
endfunction
140
140
141
141
function ! VimuxScrollUpInspect ()
142
142
call VimuxInspectRunner ()
143
- call s: VimuxTmux (' last-' .s : VimuxRunnerType() )
143
+ call s: VimuxTmux (' last-' .g : VimuxRunnerType )
144
144
call VimuxSendKeys (' C-u' )
145
145
endfunction
146
146
147
147
function ! VimuxScrollDownInspect ()
148
148
call VimuxInspectRunner ()
149
- call s: VimuxTmux (' last-' .s : VimuxRunnerType() )
149
+ call s: VimuxTmux (' last-' .g : VimuxRunnerType )
150
150
call VimuxSendKeys (' C-d' )
151
151
endfunction
152
152
@@ -168,23 +168,23 @@ endfunction
168
168
169
169
function ! VimuxPromptCommand (... )
170
170
let command = a: 0 == # 1 ? a: 1 : ' '
171
- let l: command = input (s: VimuxOption ( ' g:VimuxPromptString' , ' Command? ' ) , command , ' shellcmd' )
171
+ let l: command = input (g: VimuxPromptString , command , ' shellcmd' )
172
172
call VimuxRunCommand (l: command )
173
173
endfunction
174
174
175
175
function ! s: VimuxTmux (arguments)
176
- if s: VimuxOption ( ' g:VimuxDebug' , 0 ) != 0
177
- echom s: VimuxTmuxCmd () .' ' .a: arguments
176
+ if g: VimuxDebug
177
+ echom g: VimuxTmuxCommand .' ' .a: arguments
178
178
endif
179
- return system (s: VimuxTmuxCmd () .' ' .a: arguments )
179
+ return system (g: VimuxTmuxCommand .' ' .a: arguments )
180
180
endfunction
181
181
182
182
function ! s: VimuxTmuxSession ()
183
183
return s: VimuxTmuxProperty (' #S' )
184
184
endfunction
185
185
186
186
function ! s: VimuxTmuxIndex ()
187
- if s : VimuxRunnerType() == # ' pane'
187
+ if g : VimuxRunnerType == # ' pane'
188
188
return s: VimuxTmuxPaneId ()
189
189
else
190
190
return s: VimuxTmuxWindowId ()
@@ -200,7 +200,7 @@ function! s:VimuxTmuxWindowId()
200
200
endfunction
201
201
202
202
function ! s: VimuxNearestIndex ()
203
- let t = s : VimuxRunnerType()
203
+ let t = g : VimuxRunnerType
204
204
let filter = s: VimuxGetTargetFilter ()
205
205
let views = split (s: VimuxTmux (' list-' .t ." s -F '#{" .t .' _active}:#{' .t ." _id}'" .filter ), ' \n' )
206
206
@@ -214,11 +214,11 @@ function! s:VimuxNearestIndex()
214
214
endfunction
215
215
216
216
function ! s: VimuxGetTargetFilter ()
217
- let targetName = s: VimuxOption ( ' g:VimuxRunnerName' , ' ' )
217
+ let targetName = g: VimuxRunnerName
218
218
if targetName == # ' '
219
219
return ' '
220
220
endif
221
- let t = s : VimuxRunnerType()
221
+ let t = g : VimuxRunnerType
222
222
if t == # ' window'
223
223
return " -f '#{==:#{window_name}," .targetName." }'"
224
224
elseif t == # ' pane'
@@ -227,28 +227,23 @@ function! s:VimuxGetTargetFilter()
227
227
endfunction
228
228
229
229
function ! s: VimuxSetRunnerName ()
230
- let targetName = s: VimuxOption ( ' g:VimuxRunnerName' , ' ' )
230
+ let targetName = g: VimuxRunnerName
231
231
if targetName == # ' '
232
232
return
233
233
endif
234
- let t = s : VimuxRunnerType()
234
+ let t = g : VimuxRunnerType
235
235
if t == # ' window'
236
236
call s: VimuxTmux (' rename-window ' .targetName)
237
237
elseif t == # ' pane'
238
238
call s: VimuxTmux (' select-pane -T ' .targetName)
239
239
endif
240
240
endfunction
241
241
242
-
243
- function ! s: VimuxRunnerType ()
244
- return s: VimuxOption (' g:VimuxRunnerType' , ' pane' )
245
- endfunction
246
-
247
242
function ! s: VimuxTmuxProperty (property)
248
243
return substitute (s: VimuxTmux (" display -p '" .a: property ." '" ), ' \n$' , ' ' , ' ' )
249
244
endfunction
250
245
251
246
function ! s: VimuxHasRunner (index )
252
- let t = s : VimuxRunnerType()
247
+ let t = g : VimuxRunnerType
253
248
return match (s: VimuxTmux (' list-' .t ." s -F '#{" .t ." _id}'" ), a: index )
254
249
endfunction
0 commit comments