summaryrefslogtreecommitdiff
path: root/data/vim/patches/8.1.0141
blob: 40b1a677554da4e3eb49cf9725030b5ab8623309 (plain)
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
To: vim_dev@googlegroups.com
Subject: Patch 8.1.0141
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.0141
Problem:    :cexpr no longer jumps to the first error.
Solution:   Use the quickfix list identifier. (Yegappan Lakshmanan,
            closes #3092)
Files:	    src/quickfix.c, src/testdir/test_quickfix.vim


*** ../vim-8.1.0140/src/quickfix.c	2018-06-18 21:53:23.514826893 +0200
--- src/quickfix.c	2018-07-03 16:50:52.302649159 +0200
***************
*** 2231,2237 ****
  }
  
  /*
!  * When loading a file from the quickfix, the auto commands may modify it.
   * This may invalidate the current quickfix entry.  This function checks
   * whether an entry is still present in the quickfix list.
   * Similar to location list.
--- 2231,2237 ----
  }
  
  /*
!  * When loading a file from the quickfix, the autocommands may modify it.
   * This may invalidate the current quickfix entry.  This function checks
   * whether an entry is still present in the quickfix list.
   * Similar to location list.
***************
*** 2579,2585 ****
      if (win->w_llist == NULL)
      {
  	win->w_llist = ll_ref;
! 	ll_ref->qf_refcount++;
      }
  }
  
--- 2579,2586 ----
      if (win->w_llist == NULL)
      {
  	win->w_llist = ll_ref;
! 	if (ll_ref != NULL)
! 	    ll_ref->qf_refcount++;
      }
  }
  
***************
*** 2986,2993 ****
  	if (curbuf == old_curbuf)
  	    setpcmark();
  
! 	qf_jump_goto_line(qf_ptr->qf_lnum, qf_ptr->qf_col, qf_ptr->qf_viscol,
! 							qf_ptr->qf_pattern);
  
  #ifdef FEAT_FOLDING
  	if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped)
--- 2987,2995 ----
  	if (curbuf == old_curbuf)
  	    setpcmark();
  
! 	if (qf_ptr != NULL)
! 	    qf_jump_goto_line(qf_ptr->qf_lnum, qf_ptr->qf_col,
! 				qf_ptr->qf_viscol, qf_ptr->qf_pattern);
  
  #ifdef FEAT_FOLDING
  	if ((fdo_flags & FDO_QUICKFIX) && old_KeyTyped)
***************
*** 4056,4061 ****
--- 4058,4078 ----
  }
  
  /*
+  * Return the quickfix/location list number with the given identifier.
+  * Returns -1 if list is not found.
+  */
+     static int
+ qf_id2nr(qf_info_T *qi, int_u qfid)
+ {
+     int		qf_idx;
+ 
+     for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++)
+ 	if (qi->qf_lists[qf_idx].qf_id == qfid)
+ 	    return qf_idx;
+     return INVALID_QFIDX;
+ }
+ 
+ /*
   * Return TRUE when using ":vimgrep" for ":grep".
   */
      int
***************
*** 4083,4088 ****
--- 4100,4106 ----
      qf_info_T	*qi = &ql_info;
      int		res;
      char_u	*au_name = NULL;
+     int_u	save_qfid;
  
      /* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */
      if (grep_internal(eap->cmdidx))
***************
*** 4161,4181 ****
  					    && eap->cmdidx != CMD_lgrepadd),
  					   qf_cmdtitle(*eap->cmdlinep), enc);
      if (wp != NULL)
  	qi = GET_LOC_LIST(wp);
!     if (res >= 0 && qi != NULL)
  	qf_list_changed(qi, qi->qf_curlist);
      if (au_name != NULL)
-     {
  	apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
  					       curbuf->b_fname, TRUE, curbuf);
! 	if (qi != NULL && qi->qf_curlist < qi->qf_listcount)
! 	    res = qi->qf_lists[qi->qf_curlist].qf_count;
! 	else
! 	    res = 0;
!     }
!     if (res > 0 && !eap->forceit)
  	qf_jump(qi, 0, 0, FALSE);		/* display first error */
  
      mch_remove(fname);
      vim_free(fname);
      vim_free(cmd);
--- 4179,4206 ----
  					    && eap->cmdidx != CMD_lgrepadd),
  					   qf_cmdtitle(*eap->cmdlinep), enc);
      if (wp != NULL)
+     {
  	qi = GET_LOC_LIST(wp);
! 	if (qi == NULL)
! 	    goto cleanup;
!     }
!     if (res >= 0)
  	qf_list_changed(qi, qi->qf_curlist);
+     // Remember the current quickfix list identifier, so that we can
+     // check for autocommands changing the current quickfix list.
+     save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
      if (au_name != NULL)
  	apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
  					       curbuf->b_fname, TRUE, curbuf);
!     if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid))
!     {
! 	// If autocommands changed the current list, then restore it
! 	if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
! 	    qi->qf_curlist = qf_id2nr(qi, save_qfid);
  	qf_jump(qi, 0, 0, FALSE);		/* display first error */
+     }
  
+ cleanup:
      mch_remove(fname);
      vim_free(fname);
      vim_free(cmd);
***************
*** 4502,4508 ****
      win_T	*wp = NULL;
      qf_info_T	*qi = &ql_info;
      char_u	*au_name = NULL;
!     int		save_qfid = 0;  /* init for gcc */
      int		res;
  
      switch (eap->cmdidx)
--- 4527,4533 ----
      win_T	*wp = NULL;
      qf_info_T	*qi = &ql_info;
      char_u	*au_name = NULL;
!     int_u	save_qfid = 0;		/* init for gcc */
      int		res;
  
      switch (eap->cmdidx)
***************
*** 4555,4589 ****
  			&& eap->cmdidx != CMD_laddfile),
  			qf_cmdtitle(*eap->cmdlinep), enc);
      if (wp != NULL)
  	qi = GET_LOC_LIST(wp);
!     if (res >= 0 && qi != NULL)
  	qf_list_changed(qi, qi->qf_curlist);
!     if (qi != NULL)
! 	save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
      if (au_name != NULL)
  	apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
  
!     /* An autocmd might have freed the quickfix/location list. Check whether it
!      * is still valid. */
!     if (qi != NULL && !qflist_valid(wp, save_qfid))
! 	return;
!     if (res > 0 && (eap->cmdidx == CMD_cfile || eap->cmdidx == CMD_lfile))
  	qf_jump(qi, 0, 0, eap->forceit);	/* display first error */
! }
! 
! /*
!  * Return the quickfix/location list number with the given identifier.
!  * Returns -1 if list is not found.
!  */
!     static int
! qf_id2nr(qf_info_T *qi, int_u qfid)
! {
!     int		qf_idx;
! 
!     for (qf_idx = 0; qf_idx < qi->qf_listcount; qf_idx++)
! 	if (qi->qf_lists[qf_idx].qf_id == qfid)
! 	    return qf_idx;
!     return INVALID_QFIDX;
  }
  
  /*
--- 4580,4606 ----
  			&& eap->cmdidx != CMD_laddfile),
  			qf_cmdtitle(*eap->cmdlinep), enc);
      if (wp != NULL)
+     {
  	qi = GET_LOC_LIST(wp);
! 	if (qi == NULL)
! 	    return;
!     }
!     if (res >= 0)
  	qf_list_changed(qi, qi->qf_curlist);
!     save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
      if (au_name != NULL)
  	apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
  
!     // Jump to the first error for a new list and if autocmds didn't
!     // free the list.
!     if (res > 0 && (eap->cmdidx == CMD_cfile || eap->cmdidx == CMD_lfile)
! 	    && qflist_valid(wp, save_qfid))
!     {
! 	// If autocommands changed the current list, then restore it
! 	if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
! 	    qi->qf_curlist = qf_id2nr(qi, save_qfid);
  	qf_jump(qi, 0, 0, eap->forceit);	/* display first error */
!     }
  }
  
  /*
***************
*** 5070,5075 ****
--- 5087,5096 ----
      if (!qflist_valid(wp, save_qfid))
  	goto theend;
  
+     // If autocommands changed the current list, then restore it
+     if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
+ 	qi->qf_curlist = qf_id2nr(qi, save_qfid);
+ 
      /* Jump to first match. */
      if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
      {
***************
*** 5162,5168 ****
      /* need to open the memfile before putting the buffer in a window */
      if (ml_open(newbuf) == OK)
      {
! 	/* Make sure this buffer isn't wiped out by auto commands. */
  	++newbuf->b_locked;
  
  	/* set curwin/curbuf to buf and save a few things */
--- 5183,5189 ----
      /* need to open the memfile before putting the buffer in a window */
      if (ml_open(newbuf) == OK)
      {
! 	/* Make sure this buffer isn't wiped out by autocommands. */
  	++newbuf->b_locked;
  
  	/* set curwin/curbuf to buf and save a few things */
***************
*** 6205,6210 ****
--- 6226,6233 ----
      qf_info_T	*qi = &ql_info;
      char_u	*au_name = NULL;
      int		res;
+     int_u	save_qfid;
+     win_T	*wp = NULL;
  
      switch (eap->cmdidx)
      {
***************
*** 6233,6238 ****
--- 6256,6262 ----
  	qi = ll_get_or_alloc_list(curwin);
  	if (qi == NULL)
  	    return;
+ 	wp = curwin;
      }
  
      if (*eap->arg == NUL)
***************
*** 6271,6276 ****
--- 6295,6304 ----
  						   qf_title, NULL);
  	    if (res >= 0)
  		qf_list_changed(qi, qi->qf_curlist);
+ 
+ 	    // Remember the current quickfix list identifier, so that we can
+ 	    // check for autocommands changing the current quickfix list.
+ 	    save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
  	    if (au_name != NULL)
  	    {
  		buf_T *curbuf_old = curbuf;
***************
*** 6282,6290 ****
  		    // be invalid.
  		    res = 0;
  	    }
  	    if (res > 0 && (eap->cmdidx == CMD_cbuffer ||
! 						eap->cmdidx == CMD_lbuffer))
  		qf_jump(qi, 0, 0, eap->forceit);  /* display first error */
  	}
      }
  }
--- 6310,6326 ----
  		    // be invalid.
  		    res = 0;
  	    }
+ 	    // Jump to the first error for a new list and if autocmds didn't
+ 	    // free the list.
  	    if (res > 0 && (eap->cmdidx == CMD_cbuffer ||
! 						eap->cmdidx == CMD_lbuffer)
! 		    && qflist_valid(wp, save_qfid))
! 	    {
! 		// If autocommands changed the current list, then restore it
! 		if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
! 		    qi->qf_curlist = qf_id2nr(qi, save_qfid);
  		qf_jump(qi, 0, 0, eap->forceit);  /* display first error */
+ 	    }
  	}
      }
  }
***************
*** 6301,6306 ****
--- 6337,6344 ----
      qf_info_T	*qi = &ql_info;
      char_u	*au_name = NULL;
      int		res;
+     int_u	save_qfid;
+     win_T	*wp = NULL;
  
      switch (eap->cmdidx)
      {
***************
*** 6328,6333 ****
--- 6366,6372 ----
  	qi = ll_get_or_alloc_list(curwin);
  	if (qi == NULL)
  	    return;
+ 	wp = curwin;
      }
  
      /* Evaluate the expression.  When the result is a string or a list we can
***************
*** 6345,6358 ****
  				 qf_cmdtitle(*eap->cmdlinep), NULL);
  	    if (res >= 0)
  		qf_list_changed(qi, qi->qf_curlist);
  	    if (au_name != NULL)
  		apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
  						curbuf->b_fname, TRUE, curbuf);
  	    if (res > 0 && (eap->cmdidx == CMD_cexpr
  						   || eap->cmdidx == CMD_lexpr)
! 		    && qi == GET_LOC_LIST(curwin))
! 		// Jump to the first error if autocmds didn't free the list.
  		qf_jump(qi, 0, 0, eap->forceit);
  	}
  	else
  	    EMSG(_("E777: String or List expected"));
--- 6384,6408 ----
  				 qf_cmdtitle(*eap->cmdlinep), NULL);
  	    if (res >= 0)
  		qf_list_changed(qi, qi->qf_curlist);
+ 
+ 	    // Remember the current quickfix list identifier, so that we can
+ 	    // check for autocommands changing the current quickfix list.
+ 	    save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
  	    if (au_name != NULL)
  		apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
  						curbuf->b_fname, TRUE, curbuf);
+ 
+ 	    // Jump to the first error for a new list and if autocmds didn't
+ 	    // free the list.
  	    if (res > 0 && (eap->cmdidx == CMD_cexpr
  						   || eap->cmdidx == CMD_lexpr)
! 		    && qflist_valid(wp, save_qfid))
! 	    {
! 		// If autocommands changed the current list, then restore it
! 		if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
! 		    qi->qf_curlist = qf_id2nr(qi, save_qfid);
  		qf_jump(qi, 0, 0, eap->forceit);
+ 	    }
  	}
  	else
  	    EMSG(_("E777: String or List expected"));
*** ../vim-8.1.0140/src/testdir/test_quickfix.vim	2018-06-18 20:52:09.553050181 +0200
--- src/testdir/test_quickfix.vim	2018-07-03 16:50:52.302649159 +0200
***************
*** 3363,3375 ****
    augroup END
  endfunc
  
! func Test_setloclist_in_aucmd()
    " This was using freed memory.
    augroup nasty
!     au * * call setloclist(0, [], 'f')
    augroup END
!   lexpr "x"
    augroup nasty
      au!
    augroup END
  endfunc
--- 3363,3486 ----
    augroup END
  endfunc
  
! " Test for an autocmd freeing the quickfix/location list when cexpr/lexpr is
! " running
! func Xexpr_acmd_freelist(cchar)
!   call s:setup_commands(a:cchar)
! 
    " This was using freed memory.
    augroup nasty
!     au * * call g:Xsetlist([], 'f')
    augroup END
!   Xexpr "x"
    augroup nasty
      au!
    augroup END
  endfunc
+ 
+ func Test_cexpr_acmd_freelist()
+   call Xexpr_acmd_freelist('c')
+   call Xexpr_acmd_freelist('l')
+ endfunc
+ 
+ " Test for commands that create a new quickfix/location list and jump to the
+ " first error automatically.
+ func Xjumpto_first_error_test(cchar)
+   call s:setup_commands(a:cchar)
+ 
+   call s:create_test_file('Xtestfile1')
+   call s:create_test_file('Xtestfile2')
+   let l = ['Xtestfile1:2:Line2', 'Xtestfile2:4:Line4']
+ 
+   " Test for cexpr/lexpr
+   enew
+   Xexpr l
+   call assert_equal('Xtestfile1', bufname(''))
+   call assert_equal(2, line('.'))
+ 
+   " Test for cfile/lfile
+   enew
+   call writefile(l, 'Xerr')
+   Xfile Xerr
+   call assert_equal('Xtestfile1', bufname(''))
+   call assert_equal(2, line('.'))
+ 
+   " Test for cbuffer/lbuffer
+   edit Xerr
+   Xbuffer
+   call assert_equal('Xtestfile1', bufname(''))
+   call assert_equal(2, line('.'))
+ 
+   call delete('Xerr')
+   call delete('Xtestfile1')
+   call delete('Xtestfile2')
+ endfunc
+ 
+ func Test_jumpto_first_error()
+   call Xjumpto_first_error_test('c')
+   call Xjumpto_first_error_test('l')
+ endfunc
+ 
+ " Test for a quickfix autocmd changing the quickfix/location list before
+ " jumping to the first error in the new list.
+ func Xautocmd_changelist(cchar)
+   call s:setup_commands(a:cchar)
+ 
+   " Test for cfile/lfile
+   call s:create_test_file('Xtestfile1')
+   call s:create_test_file('Xtestfile2')
+   Xexpr 'Xtestfile1:2:Line2'
+   autocmd QuickFixCmdPost * Xolder
+   call writefile(['Xtestfile2:4:Line4'], 'Xerr')
+   Xfile Xerr
+   call assert_equal('Xtestfile2', bufname(''))
+   call assert_equal(4, line('.'))
+   autocmd! QuickFixCmdPost
+ 
+   " Test for cbuffer/lbuffer
+   call g:Xsetlist([], 'f')
+   Xexpr 'Xtestfile1:2:Line2'
+   autocmd QuickFixCmdPost * Xolder
+   call writefile(['Xtestfile2:4:Line4'], 'Xerr')
+   edit Xerr
+   Xbuffer
+   call assert_equal('Xtestfile2', bufname(''))
+   call assert_equal(4, line('.'))
+   autocmd! QuickFixCmdPost
+ 
+   " Test for cexpr/lexpr
+   call g:Xsetlist([], 'f')
+   Xexpr 'Xtestfile1:2:Line2'
+   autocmd QuickFixCmdPost * Xolder
+   Xexpr 'Xtestfile2:4:Line4'
+   call assert_equal('Xtestfile2', bufname(''))
+   call assert_equal(4, line('.'))
+   autocmd! QuickFixCmdPost
+ 
+   " Test for grep/lgrep
+   call g:Xsetlist([], 'f')
+   Xexpr 'Xtestfile1:2:Line2'
+   autocmd QuickFixCmdPost * Xolder
+   silent Xgrep Line5 Xtestfile2
+   call assert_equal('Xtestfile2', bufname(''))
+   call assert_equal(5, line('.'))
+   autocmd! QuickFixCmdPost
+ 
+   " Test for vimgrep/lvimgrep
+   call g:Xsetlist([], 'f')
+   Xexpr 'Xtestfile1:2:Line2'
+   autocmd QuickFixCmdPost * Xolder
+   silent Xvimgrep Line5 Xtestfile2
+   call assert_equal('Xtestfile2', bufname(''))
+   call assert_equal(5, line('.'))
+   autocmd! QuickFixCmdPost
+ 
+   call delete('Xerr')
+   call delete('Xtestfile1')
+   call delete('Xtestfile2')
+ endfunc
+ 
+ func Test_autocmd_changelist()
+   call Xautocmd_changelist('c')
+   call Xautocmd_changelist('l')
+ endfunc
*** ../vim-8.1.0140/src/version.c	2018-07-03 14:48:11.877218375 +0200
--- src/version.c	2018-07-03 16:50:31.718764552 +0200
***************
*** 791,792 ****
--- 791,794 ----
  {   /* Add new patch number below this line */
+ /**/
+     141,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
175. You send yourself e-mail before you go to bed to remind you
     what to do when you wake up.

 /// 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    ///