@@ -3,20 +3,24 @@ if exists('g:loaded_vimux') || &compatible
3
3
endif
4
4
let g: loaded_vimux = 1
5
5
6
- function ! 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: tmuxCmd ()
15
- return VimuxOption (' g:VimuxTmuxCommand' , ' tmux' )
16
- endfunction
17
-
18
- if ! executable (s: tmuxCmd ())
19
- echohl ErrorMsg | echomsg ' Failed to find executable ' .s: tmuxCmd () | 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
+ function ! VimuxOption (name) abort
19
+ return get (b: , a: name , get (g: , a: name ))
20
+ endfunction
21
+
22
+ if ! executable (VimuxOption (' VimuxTmuxCommand' ))
23
+ echohl ErrorMsg | echomsg ' Failed to find executable ' .VimuxOption (' VimuxTmuxCommand' ) | echohl None
20
24
finish
21
25
endif
22
26
@@ -58,7 +62,7 @@ function! VimuxRunCommand(command, ...)
58
62
if exists (' a:1' )
59
63
let l: autoreturn = a: 1
60
64
endif
61
- let resetSequence = VimuxOption (' g: VimuxResetSequence' , ' q C-u ' )
65
+ let resetSequence = VimuxOption (' VimuxResetSequence' )
62
66
let g: VimuxLastCommand = a: command
63
67
call VimuxSendKeys (resetSequence)
64
68
call VimuxSendText (a: command )
@@ -81,66 +85,66 @@ endfunction
81
85
82
86
function ! VimuxOpenRunner ()
83
87
let nearestIndex = s: nearestIndex ()
84
- if VimuxOption (' g: VimuxUseNearest' , 1 ) == # 1 && nearestIndex != -1
88
+ if VimuxOption (' VimuxUseNearest' ) == # 1 && nearestIndex != -1
85
89
let g: VimuxRunnerIndex = nearestIndex
86
90
else
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
+ let extraArguments = VimuxOption (' VimuxOpenExtraArgs' )
92
+ if VimuxOption ( ' VimuxRunnerType ' ) == # ' pane'
93
+ let height = VimuxOption (' VimuxHeight' )
94
+ let orientation = VimuxOption (' VimuxOrientation' )
91
95
call VimuxTmux (' split-window -p ' .height.' -' .orientation.' ' .extraArguments)
92
- elseif s: runnerType ( ) == # ' window'
96
+ elseif VimuxOption ( ' VimuxRunnerType ' ) == # ' window'
93
97
call VimuxTmux (' new-window ' .extraArguments)
94
98
endif
95
99
let g: VimuxRunnerIndex = s: tmuxIndex ()
96
100
call s: setRunnerName ()
97
- call VimuxTmux (' last-' .s: runnerType ( ))
101
+ call VimuxTmux (' last-' .VimuxOption ( ' VimuxRunnerType ' ))
98
102
endif
99
103
endfunction
100
104
101
105
function ! VimuxCloseRunner ()
102
106
if exists (' g:VimuxRunnerIndex' )
103
- call VimuxTmux (' kill-' .s: runnerType ( ).' -t ' .g: VimuxRunnerIndex )
107
+ call VimuxTmux (' kill-' .VimuxOption ( ' VimuxRunnerType ' ).' -t ' .g: VimuxRunnerIndex )
104
108
unlet g: VimuxRunnerIndex
105
109
endif
106
110
endfunction
107
111
108
112
function ! VimuxTogglePane ()
109
113
if exists (' g:VimuxRunnerIndex' )
110
- if s: runnerType ( ) == # ' window'
111
- call VimuxTmux (' join-pane -d -s ' .g: VimuxRunnerIndex .' -p ' .VimuxOption (' g: VimuxHeight' , 20 ))
112
- let g: VimuxRunnerType = ' pane'
113
- elseif s: runnerType ( ) == # ' pane'
114
+ if VimuxOption ( ' VimuxRunnerType ' ) == # ' window'
115
+ call VimuxTmux (' join-pane -d -s ' .g: VimuxRunnerIndex .' -p ' .VimuxOption (' VimuxHeight' ))
116
+ let VimuxOption ( ' VimuxRunnerType' ) = ' pane'
117
+ elseif VimuxOption ( ' VimuxRunnerType ' ) == # ' pane'
114
118
let g: VimuxRunnerIndex= substitute (VimuxTmux (' break-pane -d -t ' .g: VimuxRunnerIndex ." -P -F '#{window_id}'" ), ' \n' , ' ' , ' ' )
115
- let g: VimuxRunnerType = ' window'
119
+ let VimuxOption ( ' VimuxRunnerType' ) = ' window'
116
120
endif
117
121
endif
118
122
endfunction
119
123
120
124
function ! VimuxZoomRunner ()
121
125
if exists (' g:VimuxRunnerIndex' )
122
- if s: runnerType ( ) == # ' pane'
126
+ if VimuxOption ( ' VimuxRunnerType ' ) == # ' pane'
123
127
call VimuxTmux (' resize-pane -Z -t ' .g: VimuxRunnerIndex )
124
- elseif s: runnerType ( ) == # ' window'
128
+ elseif VimuxOption ( ' VimuxRunnerType ' ) == # ' window'
125
129
call VimuxTmux (' select-window -t ' .g: VimuxRunnerIndex )
126
130
endif
127
131
endif
128
132
endfunction
129
133
130
134
function ! VimuxInspectRunner ()
131
- call VimuxTmux (' select-' .s: runnerType ( ).' -t ' .g: VimuxRunnerIndex )
135
+ call VimuxTmux (' select-' .VimuxOption ( ' VimuxRunnerType ' ).' -t ' .g: VimuxRunnerIndex )
132
136
call VimuxTmux (' copy-mode' )
133
137
endfunction
134
138
135
139
function ! VimuxScrollUpInspect ()
136
140
call VimuxInspectRunner ()
137
- call VimuxTmux (' last-' .s: runnerType ( ))
141
+ call VimuxTmux (' last-' .VimuxOption ( ' VimuxRunnerType ' ))
138
142
call VimuxSendKeys (' C-u' )
139
143
endfunction
140
144
141
145
function ! VimuxScrollDownInspect ()
142
146
call VimuxInspectRunner ()
143
- call VimuxTmux (' last-' .s: runnerType ( ))
147
+ call VimuxTmux (' last-' .VimuxOption ( ' VimuxRunnerType ' ))
144
148
call VimuxSendKeys (' C-d' )
145
149
endfunction
146
150
@@ -162,23 +166,23 @@ endfunction
162
166
163
167
function ! VimuxPromptCommand (... )
164
168
let command = a: 0 == # 1 ? a: 1 : ' '
165
- let l: command = input (VimuxOption (' g: VimuxPromptString' , ' Command? ' ), command , ' shellcmd' )
169
+ let l: command = input (VimuxOption (' VimuxPromptString' ), command , ' shellcmd' )
166
170
call VimuxRunCommand (l: command )
167
171
endfunction
168
172
169
173
function ! VimuxTmux (arguments)
170
- if VimuxOption (' g: VimuxDebug' , 0 ) != 0
171
- echom s: tmuxCmd ( ).' ' .a: arguments
174
+ if VimuxOption (' VimuxDebug' )
175
+ echom VimuxOption ( ' VimuxTmuxCommand ' ).' ' .a: arguments
172
176
endif
173
- return system (s: tmuxCmd ( ).' ' .a: arguments )
177
+ return system (VimuxOption ( ' VimuxTmuxCommand ' ).' ' .a: arguments )
174
178
endfunction
175
179
176
180
function ! s: tmuxSession ()
177
181
return s: tmuxProperty (' #S' )
178
182
endfunction
179
183
180
184
function ! s: tmuxIndex ()
181
- if s: runnerType ( ) == # ' pane'
185
+ if VimuxOption ( ' VimuxRunnerType ' ) == # ' pane'
182
186
return s: tmuxPaneId ()
183
187
else
184
188
return s: tmuxWindowId ()
@@ -194,7 +198,7 @@ function! s:tmuxWindowId()
194
198
endfunction
195
199
196
200
function ! s: nearestIndex ()
197
- let t = s: runnerType ( )
201
+ let t = VimuxOption ( ' VimuxRunnerType ' )
198
202
let filter = s: getTargetFilter ()
199
203
let views = split (VimuxTmux (' list-' .t ." s -F '#{" .t .' _active}:#{' .t ." _id}'" .filter ), ' \n' )
200
204
for view in views
@@ -206,11 +210,11 @@ function! s:nearestIndex()
206
210
endfunction
207
211
208
212
function ! s: getTargetFilter ()
209
- let targetName = VimuxOption (' g: VimuxRunnerName' , ' ' )
213
+ let targetName = VimuxOption (' VimuxRunnerName' )
210
214
if targetName == # ' '
211
215
return ' '
212
216
endif
213
- let t = s: runnerType ( )
217
+ let t = VimuxOption ( ' VimuxRunnerType ' )
214
218
if t == # ' window'
215
219
return " -f '#{==:#{window_name}," .targetName." }'"
216
220
elseif t == # ' pane'
@@ -219,27 +223,23 @@ function! s:getTargetFilter()
219
223
endfunction
220
224
221
225
function ! s: setRunnerName ()
222
- let targetName = VimuxOption (' g: VimuxRunnerName' , ' ' )
226
+ let targetName = VimuxOption (' VimuxRunnerName' )
223
227
if targetName == # ' '
224
228
return
225
229
endif
226
- let t = s: runnerType ( )
230
+ let t = VimuxOption ( ' VimuxRunnerType ' )
227
231
if t == # ' window'
228
232
call VimuxTmux (' rename-window ' .targetName)
229
233
elseif t == # ' pane'
230
234
call VimuxTmux (' select-pane -T ' .targetName)
231
235
endif
232
236
endfunction
233
237
234
- function ! s: runnerType ()
235
- return VimuxOption (' g:VimuxRunnerType' , ' pane' )
236
- endfunction
237
-
238
238
function ! s: tmuxProperty (property)
239
239
return substitute (VimuxTmux (" display -p '" .a: property ." '" ), ' \n$' , ' ' , ' ' )
240
240
endfunction
241
241
242
242
function ! s: hasRunner (index )
243
- let t = s: runnerType ( )
243
+ let t = VimuxOption ( ' VimuxRunnerType ' )
244
244
return match (VimuxTmux (' list-' .t ." s -F '#{" .t ." _id}'" ), a: index )
245
245
endfunction
0 commit comments