1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0523
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------
Patch 8.1.0523
Problem: Opening window from quickfix leaves empty buffer behind.
Solution: Add qf_jump_newwin(). (Yegappan Lakshmanan, closes #2574)
Files: src/proto/quickfix.pro, src/quickfix.c,
src/testdir/test_quickfix.vim
*** ../vim-8.1.0522/src/proto/quickfix.pro 2018-10-20 20:53:58.143284832 +0200
--- src/proto/quickfix.pro 2018-11-11 22:45:31.145846186 +0100
***************
*** 4,9 ****
--- 4,10 ----
void check_quickfix_busy(void);
void copy_loclist_stack(win_T *from, win_T *to);
void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit);
+ void qf_jump_newwin(qf_info_T *qi, int dir, int errornr, int forceit, int newwin);
void qf_list(exarg_T *eap);
void qf_age(exarg_T *eap);
void qf_history(exarg_T *eap);
*** ../vim-8.1.0522/src/quickfix.c 2018-10-28 14:36:04.222247691 +0100
--- src/quickfix.c 2018-11-11 22:46:08.525548009 +0100
***************
*** 2699,2713 ****
}
/*
! * Find a help window or open one.
*/
static int
! jump_to_help_window(qf_info_T *qi, int *opened_window)
{
win_T *wp;
int flags;
! if (cmdmod.tab != 0)
wp = NULL;
else
wp = qf_find_help_win();
--- 2699,2714 ----
}
/*
! * Find a help window or open one. If 'newwin' is TRUE, then open a new help
! * window.
*/
static int
! jump_to_help_window(qf_info_T *qi, int newwin, int *opened_window)
{
win_T *wp;
int flags;
! if (cmdmod.tab != 0 || newwin)
wp = NULL;
else
wp = qf_find_help_win();
***************
*** 2721,2728 ****
if (cmdmod.split == 0 && curwin->w_width != Columns
&& curwin->w_width < 80)
flags |= WSP_TOP;
! if (IS_LL_STACK(qi))
! flags |= WSP_NEWLOC; // don't copy the location list
if (win_split(0, flags) == FAIL)
return FAIL;
--- 2722,2731 ----
if (cmdmod.split == 0 && curwin->w_width != Columns
&& curwin->w_width < 80)
flags |= WSP_TOP;
! // If the user asks to open a new window, then copy the location list.
! // Otherwise, don't copy the location list.
! if (IS_LL_STACK(qi) && !newwin)
! flags |= WSP_NEWLOC;
if (win_split(0, flags) == FAIL)
return FAIL;
***************
*** 2732,2740 ****
if (curwin->w_height < p_hh)
win_setheight((int)p_hh);
! if (IS_LL_STACK(qi)) // not a quickfix list
{
- // The new window should use the supplied location list
curwin->w_llist = qi;
qi->qf_refcount++;
}
--- 2735,2745 ----
if (curwin->w_height < p_hh)
win_setheight((int)p_hh);
! // When using location list, the new window should use the supplied
! // location list. If the user asks to open a new window, then the new
! // window will get a copy of the location list.
! if (IS_LL_STACK(qi) && !newwin)
{
curwin->w_llist = qi;
qi->qf_refcount++;
}
***************
*** 2915,2934 ****
/*
* Find a suitable window for opening a file (qf_fnum) from the
* quickfix/location list and jump to it. If the file is already opened in a
! * window, jump to it. Otherwise open a new window to display the file. This is
! * called from either a quickfix or a location list window.
*/
static int
! qf_jump_to_usable_window(int qf_fnum, int *opened_window)
{
win_T *usable_win_ptr = NULL;
int usable_win;
! qf_info_T *ll_ref;
win_T *win;
usable_win = 0;
! ll_ref = curwin->w_llist_ref;
if (ll_ref != NULL)
{
// Find a non-quickfix window with this location list
--- 2920,2945 ----
/*
* Find a suitable window for opening a file (qf_fnum) from the
* quickfix/location list and jump to it. If the file is already opened in a
! * window, jump to it. Otherwise open a new window to display the file. If
! * 'newwin' is TRUE, then always open a new window. This is called from either
! * a quickfix or a location list window.
*/
static int
! qf_jump_to_usable_window(int qf_fnum, int newwin, int *opened_window)
{
win_T *usable_win_ptr = NULL;
int usable_win;
! qf_info_T *ll_ref = NULL;
win_T *win;
usable_win = 0;
! // If opening a new window, then don't use the location list referred by
! // the current window. Otherwise two windows will refer to the same
! // location list.
! if (!newwin)
! ll_ref = curwin->w_llist_ref;
!
if (ll_ref != NULL)
{
// Find a non-quickfix window with this location list
***************
*** 2952,2958 ****
// If there is only one window and it is the quickfix window, create a
// new one above the quickfix window.
! if ((ONE_WINDOW && bt_quickfix(curbuf)) || !usable_win)
{
if (qf_open_new_file_win(ll_ref) != OK)
return FAIL;
--- 2963,2969 ----
// If there is only one window and it is the quickfix window, create a
// new one above the quickfix window.
! if ((ONE_WINDOW && bt_quickfix(curbuf)) || !usable_win || newwin)
{
if (qf_open_new_file_win(ll_ref) != OK)
return FAIL;
***************
*** 3146,3162 ****
/*
* Find a usable window for opening a file from the quickfix/location list. If
! * a window is not found then open a new window.
* Returns OK if successfully jumped or opened a window. Returns FAIL if not
* able to jump/open a window. Returns NOTDONE if a file is not associated
* with the entry.
*/
static int
! qf_jump_open_window(qf_info_T *qi, qfline_T *qf_ptr, int *opened_window)
{
// For ":helpgrep" find a help window or open one.
if (qf_ptr->qf_type == 1 && (!bt_help(curwin->w_buffer) || cmdmod.tab != 0))
! if (jump_to_help_window(qi, opened_window) == FAIL)
return FAIL;
// If currently in the quickfix window, find another window to show the
--- 3157,3178 ----
/*
* Find a usable window for opening a file from the quickfix/location list. If
! * a window is not found then open a new window. If 'newwin' is TRUE, then open
! * a new window.
* Returns OK if successfully jumped or opened a window. Returns FAIL if not
* able to jump/open a window. Returns NOTDONE if a file is not associated
* with the entry.
*/
static int
! qf_jump_open_window(
! qf_info_T *qi,
! qfline_T *qf_ptr,
! int newwin,
! int *opened_window)
{
// For ":helpgrep" find a help window or open one.
if (qf_ptr->qf_type == 1 && (!bt_help(curwin->w_buffer) || cmdmod.tab != 0))
! if (jump_to_help_window(qi, newwin, opened_window) == FAIL)
return FAIL;
// If currently in the quickfix window, find another window to show the
***************
*** 3168,3174 ****
if (qf_ptr->qf_fnum == 0)
return NOTDONE;
! if (qf_jump_to_usable_window(qf_ptr->qf_fnum, opened_window) == FAIL)
return FAIL;
}
--- 3184,3191 ----
if (qf_ptr->qf_fnum == 0)
return NOTDONE;
! if (qf_jump_to_usable_window(qf_ptr->qf_fnum, newwin,
! opened_window) == FAIL)
return FAIL;
}
***************
*** 3229,3241 ****
}
/*
! * jump to a quickfix line
! * if dir == FORWARD go "errornr" valid entries forward
! * if dir == BACKWARD go "errornr" valid entries backward
! * if dir == FORWARD_FILE go "errornr" valid entries files backward
! * if dir == BACKWARD_FILE go "errornr" valid entries files backward
* else if "errornr" is zero, redisplay the same line
! * else go to entry "errornr"
*/
void
qf_jump(qf_info_T *qi,
--- 3246,3258 ----
}
/*
! * Jump to a quickfix line.
! * If dir == FORWARD go "errornr" valid entries forward.
! * If dir == BACKWARD go "errornr" valid entries backward.
! * If dir == FORWARD_FILE go "errornr" valid entries files backward.
! * If dir == BACKWARD_FILE go "errornr" valid entries files backward
* else if "errornr" is zero, redisplay the same line
! * else go to entry "errornr".
*/
void
qf_jump(qf_info_T *qi,
***************
*** 3243,3248 ****
--- 3260,3279 ----
int errornr,
int forceit)
{
+ qf_jump_newwin(qi, dir, errornr, forceit, FALSE);
+ }
+
+ /*
+ * As qf_info().
+ * If 'newwin' is TRUE, then open the file in a new window.
+ */
+ void
+ qf_jump_newwin(qf_info_T *qi,
+ int dir,
+ int errornr,
+ int forceit,
+ int newwin)
+ {
qf_list_T *qfl;
qfline_T *qf_ptr;
qfline_T *old_qf_ptr;
***************
*** 3288,3294 ****
// window
print_message = FALSE;
! retval = qf_jump_open_window(qi, qf_ptr, &opened_window);
if (retval == FAIL)
goto failed;
if (retval == NOTDONE)
--- 3319,3325 ----
// window
print_message = FALSE;
! retval = qf_jump_open_window(qi, qf_ptr, newwin, &opened_window);
if (retval == FAIL)
goto failed;
if (retval == NOTDONE)
***************
*** 3824,3836 ****
if (split)
{
! char_u cmd[32];
!
! vim_snprintf((char *)cmd, sizeof(cmd), "split +%ld%s",
! (long)curwin->w_cursor.lnum,
! IS_LL_WINDOW(curwin) ? "ll" : "cc");
! if (do_cmdline_cmd(cmd) == OK)
! do_cmdline_cmd((char_u *) "clearjumps");
return;
}
--- 3855,3863 ----
if (split)
{
! // Open the selected entry in a new window
! qf_jump_newwin(qi, 0, (long)curwin->w_cursor.lnum, FALSE, TRUE);
! do_cmdline_cmd((char_u *) "clearjumps");
return;
}
*** ../vim-8.1.0522/src/testdir/test_quickfix.vim 2018-10-28 14:36:04.222247691 +0100
--- src/testdir/test_quickfix.vim 2018-11-11 22:46:08.525548009 +0100
***************
*** 3718,3720 ****
--- 3718,3766 ----
call assert_equal(getcurpos()[4], virtcol('.'))
cclose | helpclose
endfunc
+
+ " Test for opening a file from the quickfix window using CTRL-W <Enter>
+ " doesn't leave an empty buffer around.
+ func Test_splitview()
+ call s:create_test_file('Xtestfile1')
+ call s:create_test_file('Xtestfile2')
+ new | only
+ let last_bufnr = bufnr('Test_sv_1', 1)
+ let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
+ cgetexpr l
+ copen
+ let numbufs = len(getbufinfo())
+ exe "normal \<C-W>\<CR>"
+ copen
+ exe "normal j\<C-W>\<CR>"
+ " Make sure new empty buffers are not created
+ call assert_equal(numbufs, len(getbufinfo()))
+ " Creating a new buffer should use the next available buffer number
+ call assert_equal(last_bufnr + 4, bufnr("Test_sv_2", 1))
+ bwipe Test_sv_1
+ bwipe Test_sv_2
+ new | only
+
+ " When split opening files from location list window, make sure that two
+ " windows doesn't refer to the same location list
+ lgetexpr l
+ let locid = getloclist(0, {'id' : 0}).id
+ lopen
+ exe "normal \<C-W>\<CR>"
+ call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
+ call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
+ new | only
+
+ " When split opening files from a helpgrep location list window, a new help
+ " window should be opend with a copy of the location list.
+ lhelpgrep window
+ let locid = getloclist(0, {'id' : 0}).id
+ lwindow
+ exe "normal j\<C-W>\<CR>"
+ call assert_notequal(locid, getloclist(0, {'id' : 0}).id)
+ call assert_equal(0, getloclist(0, {'winid' : 0}).winid)
+ new | only
+
+ call delete('Xtestfile1')
+ call delete('Xtestfile2')
+ endfunc
*** ../vim-8.1.0522/src/version.c 2018-11-11 22:18:17.214948188 +0100
--- src/version.c 2018-11-11 22:49:25.382976159 +0100
***************
*** 794,795 ****
--- 794,797 ----
{ /* Add new patch number below this line */
+ /**/
+ 523,
/**/
--
ARTHUR: Bloody peasant!
DENNIS: Oh, what a give away. Did you hear that, did you hear that, eh?
That's what I'm on about -- did you see him repressing me, you saw it
didn't you?
The Quest for the Holy Grail (Monty Python)
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|