Hi,

On Sun, Apr 17, 2016 at 5:47 PM, Ramel Eshed <[email protected]> wrote:
>> >>> > Hi,
>> >>> >
>> >>> > On Sat, Apr 16, 2016 at 12:52 PM, Ramel Eshed <[email protected]> 
>> >>> > wrote:
>> >>> >> Adding an item to the current quickfix list causes a jump to the 
>> >>> >> first item rather than keeping the current context:
>> >>> >>
>> >>> >> Download the attached file;
>> >>> >> vim -u NONE -N
>> >>> >> :source qf_test.vim
>> >>> >>
>> >>> >> -After adding 2 items, :cn, adding one more item and another :cn we 
>> >>> >> are in (2 of 3) instead of (3 of 3).
>> >>> >>
>> >>> >
>> >>> > The setqflist() function resets the index of the quickfix list so that 
>> >>> > it
>> >>> > points to the first entry (even if entries are appended to the list).
>> >>> >
>> >>> > Due to a bug in the set_errorlist() function, the index is set to 1 
>> >>> > instead
>> >>> > of zero. That is why, you saw 2 of 3 instead of 1 of 3.
>> >>> >
>> >>>
>> >>> The quickfix index is 1 based and not zero based. The current code 
>> >>> correctly
>> >>> sets the index to 1. So there is no bug in the current code.
>> >>>
>> >>> The documentation for the setqflist() function needs to be updated to
>> >>> state that it will reset to the first valid entry.
>> >>>
>> >>> - Yegappan
>> >>
>> >> Is there any reason to reset the pointer each time? I think that it is
>> >> more reasonable to leave the pointer as it when adding to the list so
>> >> it’d be possible to work with the list and adding new items to it when
>> >> they’re available without losing the context.
>> >>
>> >
>> > Agreed. I will send out a patch later today for this.
>> >
>>
>> A patch with tests is attached.
>>
>> - Yegappan
>>
>> >
>> >>
>> >> What I’m trying to do is to start a job that will search in a large
>> >> code base and to be able to work with the available results as they
>> >> appear. I don’t want to wait for the entire search to complete. Now,
>> >> when trying to call setqflist(…, ‘a’) from the job’s callback I can’t
>> >> really work with the results that already arrived.
>> >>
>> >
>> > Makes sense.
>> >
>
> Great! Thanks Yegappan, this is a really nice feature I've been waiting to 
> see for years.
>
> There is one more minor issue though, with the quickfix window. Each
> addition puts the cursor at the line of the current item so it is not
> possible to navigate inside the quickfix window while the results are
> being added (with hjkl, for example. only :cn is working). Could you
> please fix that as well?
>

An updated patch that fixes the above issue is attached. Let me know if
you run into any issues.

- Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/src/quickfix.c b/src/quickfix.c
index 00762bd..510d8dd 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -126,7 +126,7 @@ static int  qf_win_pos_update(qf_info_T *qi, int 
old_qf_index);
 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
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 8da1b6f..d32c4a7 100644
--- 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 = 'setqflist('
+    let Xgetlist = 'getqflist()'
+    let Xnext = 'cnext'
+  else
+    let Xsetlist = 'setloclist(0,'
+    let Xgetlist = 'getloclist(0)'
+    let Xnext = 'lnext'
+  endif
+
+  exe 'call ' . Xsetlist . "[{'bufnr': a:bnum, 'lnum': 1}," .
+             \   "{'bufnr': a:bnum, 'lnum': 2}])"
+  exe 'let l = ' . Xgetlist
+  call assert_equal(2, len(l))
+  call assert_equal(2, l[1].lnum)
+
+  exe Xnext
+  exe 'call ' . Xsetlist . "[{'bufnr': a:bnum, 'lnum': 3}], 'a')"
+  exe 'let l = ' . Xgetlist
+  call assert_equal(3, len(l))
+  exe Xnext
+  call assert_equal(3, line('.'))
+
+  exe 'call ' . Xsetlist . "[{'bufnr': a:bnum, 'lnum': 3}," .
+             \   "{'bufnr': a:bnum, 'lnum': 4}," .
+             \   "{'bufnr': a:bnum, 'lnum': 5}], 'r')"
+  exe 'let l = ' . Xgetlist
+  call assert_equal(3, len(l))
+  call assert_equal(5, l[2].lnum)
+
+  exe 'call ' . Xsetlist . "[])"
+  exe '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

Raspunde prin e-mail lui