Skip to content

Commit c1808d5

Browse files
committed
patch 7.4.1752
Problem: When adding to the quickfix list the current position is reset. Solution: Do not reset the position when not needed. (Yegappan Lakshmanan)
1 parent def5abe commit c1808d5

3 files changed

Lines changed: 66 additions & 11 deletions

File tree

src/quickfix.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static int qf_win_pos_update(qf_info_T *qi, int old_qf_index);
126126
static int is_qf_win(win_T *win, qf_info_T *qi);
127127
static win_T *qf_find_win(qf_info_T *qi);
128128
static buf_T *qf_find_buf(qf_info_T *qi);
129-
static void qf_update_buffer(qf_info_T *qi);
129+
static void qf_update_buffer(qf_info_T *qi, int update_cursor);
130130
static void qf_set_title_var(qf_info_T *qi);
131131
static void qf_fill_buffer(qf_info_T *qi);
132132
#endif
@@ -880,7 +880,7 @@ qf_init_ext(
880880
vim_free(fmtstr);
881881

882882
#ifdef FEAT_WINDOWS
883-
qf_update_buffer(qi);
883+
qf_update_buffer(qi, TRUE);
884884
#endif
885885

886886
return retval;
@@ -2176,7 +2176,7 @@ qf_msg(qf_info_T *qi)
21762176
qi->qf_curlist + 1, qi->qf_listcount,
21772177
qi->qf_lists[qi->qf_curlist].qf_count);
21782178
#ifdef FEAT_WINDOWS
2179-
qf_update_buffer(qi);
2179+
qf_update_buffer(qi, TRUE);
21802180
#endif
21812181
}
21822182

@@ -2606,7 +2606,7 @@ qf_find_buf(qf_info_T *qi)
26062606
* Find the quickfix buffer. If it exists, update the contents.
26072607
*/
26082608
static void
2609-
qf_update_buffer(qf_info_T *qi)
2609+
qf_update_buffer(qf_info_T *qi, int update_cursor)
26102610
{
26112611
buf_T *buf;
26122612
win_T *win;
@@ -2633,7 +2633,8 @@ qf_update_buffer(qf_info_T *qi)
26332633
/* restore curwin/curbuf and a few other things */
26342634
aucmd_restbuf(&aco);
26352635

2636-
(void)qf_win_pos_update(qi, 0);
2636+
if (update_cursor)
2637+
(void)qf_win_pos_update(qi, 0);
26372638
}
26382639
}
26392640

@@ -3675,7 +3676,7 @@ ex_vimgrep(exarg_T *eap)
36753676
qi->qf_lists[qi->qf_curlist].qf_index = 1;
36763677

36773678
#ifdef FEAT_WINDOWS
3678-
qf_update_buffer(qi);
3679+
qf_update_buffer(qi, TRUE);
36793680
#endif
36803681

36813682
#ifdef FEAT_AUTOCMD
@@ -4115,12 +4116,16 @@ set_errorlist(
41154116
qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE;
41164117
else
41174118
qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
4118-
qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start;
4119-
if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
4120-
qi->qf_lists[qi->qf_curlist].qf_index = 1;
4119+
if (action != 'a') {
4120+
qi->qf_lists[qi->qf_curlist].qf_ptr =
4121+
qi->qf_lists[qi->qf_curlist].qf_start;
4122+
if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
4123+
qi->qf_lists[qi->qf_curlist].qf_index = 1;
4124+
}
41214125

41224126
#ifdef FEAT_WINDOWS
4123-
qf_update_buffer(qi);
4127+
/* Don't update the cursor in quickfix window when appending entries */
4128+
qf_update_buffer(qi, (action != 'a'));
41244129
#endif
41254130

41264131
return retval;
@@ -4427,7 +4432,7 @@ ex_helpgrep(exarg_T *eap)
44274432
free_string_option(save_cpo);
44284433

44294434
#ifdef FEAT_WINDOWS
4430-
qf_update_buffer(qi);
4435+
qf_update_buffer(qi, TRUE);
44314436
#endif
44324437

44334438
#ifdef FEAT_AUTOCMD

src/testdir/test_quickfix.vim

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,3 +697,51 @@ func Test_cgetexpr_works()
697697
" this must not crash Vim
698698
cgetexpr [$x]
699699
endfunc
700+
701+
" Tests for the setqflist() and setloclist() functions
702+
function SetXlistTests(cchar, bnum)
703+
if a:cchar == 'c'
704+
let Xsetlist = function('setqflist')
705+
let Xgetlist = function('getqflist')
706+
let Xnext = 'cnext'
707+
else
708+
let Xsetlist = function('setloclist', [0])
709+
let Xgetlist = function('getloclist', [0])
710+
let Xnext = 'lnext'
711+
endif
712+
713+
call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
714+
\ {'bufnr': a:bnum, 'lnum': 2}])
715+
let l = Xgetlist()
716+
call assert_equal(2, len(l))
717+
call assert_equal(2, l[1].lnum)
718+
719+
exe Xnext
720+
call Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
721+
let l = Xgetlist()
722+
call assert_equal(3, len(l))
723+
exe Xnext
724+
call assert_equal(3, line('.'))
725+
726+
call Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
727+
\ {'bufnr': a:bnum, 'lnum': 4},
728+
\ {'bufnr': a:bnum, 'lnum': 5}], 'r')
729+
let l = Xgetlist()
730+
call assert_equal(3, len(l))
731+
call assert_equal(5, l[2].lnum)
732+
733+
call Xsetlist([])
734+
let l = Xgetlist()
735+
call assert_equal(0, len(l))
736+
endfunction
737+
738+
function Test_setqflist()
739+
new Xtestfile | only
740+
let bnum = bufnr('%')
741+
call setline(1, range(1,5))
742+
743+
call SetXlistTests('c', bnum)
744+
call SetXlistTests('l', bnum)
745+
746+
call delete('Xtestfile')
747+
endfunction

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static char *(features[]) =
748748

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1752,
751753
/**/
752754
1751,
753755
/**/

0 commit comments

Comments
 (0)