Hi all,
On Wed, Mar 22, 2017 at 2:30 PM, Bram Moolenaar <[email protected]> wrote:
>
> Yegappan wrote:
>
>> >> When developing additional tests for the quickfix functionality,
>> >> I found that some part of the code checks whether the quickfix
>> >> or location list stack is empty. To test for these conditions, we
>> >> need a function to delete the quickfix and location list stacks.
>> >>
>> >> What about extending the setqflist() and setloclist() functions
>> >> to add support for deleting a list? If the action parameter is 'd',
>> >> then delete the last quickfix/location list. If the action
>> >> parameter is 'w', then wipe out the entire list.
>> >>
>> >> setqflist([], 'd') - Delete the last quickfix list.
>> >> setqflist([], 'w') - Wipe out the quickfix stack.
>> >> setloclist(0, [], 'd') - Delete the last location list.
>> >> setloclist(0, [], 'w') - Wipe out the location list stack.
>> >>
>> >> Do you have any other suggestions?
>> >
>> > Does this have any other use than for testing? If not, then I would
>> > keep it as simple as possible. Perhaps we don't need the "w" argument?
>> >
>>
>> The attached patch adds support for freeing the quickfix stack
>> using the setqflist() function. Updated the quickfix tests to
>> make use of this functionality and added additional test cases.
>
> Thanks!
>
When freeing the quickfix stack, if the quickfix window is present, then
the quickfix window contents are not updated. Similarly the location
list window is not updated after freeing the location list stack.
The attached patch fixes these issues and adds a test.
- 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 466c5c2e8..9b056a998 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4866,9 +4866,48 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int
action)
return retval;
}
+/* Find the non-location list window with the specified location list */
+ static win_T *
+find_win_with_ll(qf_info_T *qi)
+{
+ win_T *wp = NULL;
+
+ FOR_ALL_WINDOWS(wp)
+ if ((wp->w_llist == qi) && !bt_quickfix(wp->w_buffer))
+ return wp;
+
+ return NULL;
+}
+
+/*
+ * Free the entire quickfix/location list stack.
+ * If the quickfix/location list window is open, then clear it.
+ */
static void
qf_free_stack(win_T *wp, qf_info_T *qi)
{
+ win_T *qfwin = qf_find_win(qi);
+ win_T *llwin = NULL;
+ win_T *orig_wp = wp;
+
+ if (qfwin != NULL)
+ {
+ /* If the quickfix/location list window is open, then clear it */
+ if (qi->qf_curlist < qi->qf_listcount)
+ qf_free(qi, qi->qf_curlist);
+ qf_update_buffer(qi, NULL);
+ }
+
+ if (wp && IS_LL_WINDOW(wp))
+ {
+ /* If in the location list window, then use the non-location list
+ * window with this location list (if present)
+ */
+ llwin = find_win_with_ll(qi);
+ if (llwin != NULL)
+ wp = llwin;
+ }
+
qf_free_all(wp);
if (wp == NULL)
{
@@ -4876,6 +4915,18 @@ qf_free_stack(win_T *wp, qf_info_T *qi)
qi->qf_curlist = 0;
qi->qf_listcount = 0;
}
+ else if (IS_LL_WINDOW(orig_wp))
+ {
+ /* If the location list window is open, then create a new empty
+ * location list */
+ qf_info_T *new_ll = ll_new_list();
+ orig_wp->w_llist_ref = new_ll;
+ if (llwin != NULL)
+ {
+ llwin->w_llist = new_ll;
+ new_ll->qf_refcount++;
+ }
+ }
}
/*
diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim
index 6e4b8c2b1..54995f787 100644
--- a/src/testdir/test_quickfix.vim
+++ b/src/testdir/test_quickfix.vim
@@ -1912,3 +1912,66 @@ func Test_vimgrep()
call XvimgrepTests('c')
call XvimgrepTests('l')
endfunc
+
+func XfreeTests(cchar)
+ call s:setup_commands(a:cchar)
+
+ enew | only
+
+ " Deleting the quickfix stack should work even When the current list is
+ " somewhere in the middle of the stack
+ Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
+ Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
+ Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
+ Xolder
+ call g:Xsetlist([], 'f')
+ call assert_equal(0, len(g:Xgetlist()))
+
+ " After deleting the stack, adding a new list should create a stack with a
+ " single list.
+ Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
+ call assert_equal(1, g:Xgetlist({'all':1}).nr)
+
+ " Deleting the stack from a quickfix window should update/clear the
+ " quickfix/location list window.
+ Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
+ Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
+ Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
+ Xolder
+ Xwindow
+ call g:Xsetlist([], 'f')
+ call assert_equal(2, winnr('$'))
+ call assert_equal(1, line('$'))
+ Xclose
+
+ " Deleting the stack from a non-quickfix window should update/clear the
+ " quickfix/location list window.
+ Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
+ Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
+ Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
+ Xolder
+ Xwindow
+ wincmd p
+ call g:Xsetlist([], 'f')
+ call assert_equal(0, len(g:Xgetlist()))
+ wincmd p
+ call assert_equal(2, winnr('$'))
+ call assert_equal(1, line('$'))
+
+ " After deleting the location list stack, if the location list window is
+ " opened, then a new location list should be created. So opening the
+ " location list window again should not create a new window.
+ if a:cchar == 'l'
+ lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
+ wincmd p
+ lopen
+ call assert_equal(2, winnr('$'))
+ endif
+ Xclose
+endfunc
+
+" Tests for the quickifx free functionality
+func Test_qf_free()
+ call XfreeTests('c')
+ call XfreeTests('l')
+endfunc