changeset 8932:25c2031e9f9f v7.4.1752

commit https://github.com/vim/vim/commit/c1808d5822ed9534ef7f0fe509b15bee92a5cc28 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Apr 18 20:04:00 2016 +0200 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)
author Christian Brabandt <cb@256bit.org>
date Mon, 18 Apr 2016 20:15:05 +0200
parents 20af5157c7f4
children 906f1e3bd234
files src/quickfix.c src/testdir/test_quickfix.vim src/version.c
diffstat 3 files changed, 66 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -126,7 +126,7 @@ static int	qf_win_pos_update(qf_info_T *
 static int	is_qf_win(win_T *win, qf_info_T *qi);
 static win_T	*qf_find_win(qf_info_T *qi);
 static buf_T	*qf_find_buf(qf_info_T *qi);
-static void	qf_update_buffer(qf_info_T *qi);
+static void	qf_update_buffer(qf_info_T *qi, int update_cursor);
 static void	qf_set_title_var(qf_info_T *qi);
 static void	qf_fill_buffer(qf_info_T *qi);
 #endif
@@ -880,7 +880,7 @@ qf_init_end:
     vim_free(fmtstr);
 
 #ifdef FEAT_WINDOWS
-    qf_update_buffer(qi);
+    qf_update_buffer(qi, TRUE);
 #endif
 
     return retval;
@@ -2176,7 +2176,7 @@ qf_msg(qf_info_T *qi)
 	    qi->qf_curlist + 1, qi->qf_listcount,
 	    qi->qf_lists[qi->qf_curlist].qf_count);
 #ifdef FEAT_WINDOWS
-    qf_update_buffer(qi);
+    qf_update_buffer(qi, TRUE);
 #endif
 }
 
@@ -2606,7 +2606,7 @@ qf_find_buf(qf_info_T *qi)
  * Find the quickfix buffer.  If it exists, update the contents.
  */
     static void
-qf_update_buffer(qf_info_T *qi)
+qf_update_buffer(qf_info_T *qi, int update_cursor)
 {
     buf_T	*buf;
     win_T	*win;
@@ -2633,7 +2633,8 @@ qf_update_buffer(qf_info_T *qi)
 	/* restore curwin/curbuf and a few other things */
 	aucmd_restbuf(&aco);
 
-	(void)qf_win_pos_update(qi, 0);
+	if (update_cursor)
+	    (void)qf_win_pos_update(qi, 0);
     }
 }
 
@@ -3675,7 +3676,7 @@ ex_vimgrep(exarg_T *eap)
     qi->qf_lists[qi->qf_curlist].qf_index = 1;
 
 #ifdef FEAT_WINDOWS
-    qf_update_buffer(qi);
+    qf_update_buffer(qi, TRUE);
 #endif
 
 #ifdef FEAT_AUTOCMD
@@ -4115,12 +4116,16 @@ set_errorlist(
 	qi->qf_lists[qi->qf_curlist].qf_nonevalid = TRUE;
     else
 	qi->qf_lists[qi->qf_curlist].qf_nonevalid = FALSE;
-    qi->qf_lists[qi->qf_curlist].qf_ptr = qi->qf_lists[qi->qf_curlist].qf_start;
-    if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
-	qi->qf_lists[qi->qf_curlist].qf_index = 1;
+    if (action != 'a') {
+	qi->qf_lists[qi->qf_curlist].qf_ptr =
+	    qi->qf_lists[qi->qf_curlist].qf_start;
+	if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
+	    qi->qf_lists[qi->qf_curlist].qf_index = 1;
+    }
 
 #ifdef FEAT_WINDOWS
-    qf_update_buffer(qi);
+    /* Don't update the cursor in quickfix window when appending entries */
+    qf_update_buffer(qi, (action != 'a'));
 #endif
 
     return retval;
@@ -4427,7 +4432,7 @@ ex_helpgrep(exarg_T *eap)
 	free_string_option(save_cpo);
 
 #ifdef FEAT_WINDOWS
-    qf_update_buffer(qi);
+    qf_update_buffer(qi, TRUE);
 #endif
 
 #ifdef FEAT_AUTOCMD
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -697,3 +697,51 @@ func Test_cgetexpr_works()
   " this must not crash Vim
   cgetexpr [$x]
 endfunc
+
+" Tests for the setqflist() and setloclist() functions
+function SetXlistTests(cchar, bnum)
+  if a:cchar == 'c'
+    let Xsetlist = function('setqflist')
+    let Xgetlist = function('getqflist')
+    let Xnext = 'cnext'
+  else
+    let Xsetlist = function('setloclist', [0])
+    let Xgetlist = function('getloclist', [0])
+    let Xnext = 'lnext'
+  endif
+
+  call Xsetlist([{'bufnr': a:bnum, 'lnum': 1},
+	      \  {'bufnr': a:bnum, 'lnum': 2}])
+  let l = Xgetlist()
+  call assert_equal(2, len(l))
+  call assert_equal(2, l[1].lnum)
+
+  exe Xnext
+  call Xsetlist([{'bufnr': a:bnum, 'lnum': 3}], 'a')
+  let l = Xgetlist()
+  call assert_equal(3, len(l))
+  exe Xnext
+  call assert_equal(3, line('.'))
+
+  call Xsetlist([{'bufnr': a:bnum, 'lnum': 3},
+	      \  {'bufnr': a:bnum, 'lnum': 4},
+	      \  {'bufnr': a:bnum, 'lnum': 5}], 'r')
+  let l = Xgetlist()
+  call assert_equal(3, len(l))
+  call assert_equal(5, l[2].lnum)
+
+  call Xsetlist([])
+  let l = Xgetlist()
+  call assert_equal(0, len(l))
+endfunction
+
+function Test_setqflist()
+  new Xtestfile | only
+  let bnum = bufnr('%')
+  call setline(1, range(1,5))
+
+  call SetXlistTests('c', bnum)
+  call SetXlistTests('l', bnum)
+
+  call delete('Xtestfile')
+endfunction
--- a/src/version.c
+++ b/src/version.c
@@ -749,6 +749,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1752,
+/**/
     1751,
 /**/
     1750,