Skip to content

Commit 69f40be

Browse files
committed
patch 8.0.0536: quickfix window not updated when freeing quickfix stack
Problem: Quickfix window not updated when freeing quickfix stack. Solution: Update the quickfix window. (Yegappan Lakshmanan)
1 parent 6914c64 commit 69f40be

3 files changed

Lines changed: 118 additions & 0 deletions

File tree

src/quickfix.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4866,16 +4866,69 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action)
48664866
return retval;
48674867
}
48684868

4869+
/*
4870+
* Find the non-location list window with the specified location list.
4871+
*/
4872+
static win_T *
4873+
find_win_with_ll(qf_info_T *qi)
4874+
{
4875+
win_T *wp = NULL;
4876+
4877+
FOR_ALL_WINDOWS(wp)
4878+
if ((wp->w_llist == qi) && !bt_quickfix(wp->w_buffer))
4879+
return wp;
4880+
4881+
return NULL;
4882+
}
4883+
4884+
/*
4885+
* Free the entire quickfix/location list stack.
4886+
* If the quickfix/location list window is open, then clear it.
4887+
*/
48694888
static void
48704889
qf_free_stack(win_T *wp, qf_info_T *qi)
48714890
{
4891+
win_T *qfwin = qf_find_win(qi);
4892+
win_T *llwin = NULL;
4893+
win_T *orig_wp = wp;
4894+
4895+
if (qfwin != NULL)
4896+
{
4897+
/* If the quickfix/location list window is open, then clear it */
4898+
if (qi->qf_curlist < qi->qf_listcount)
4899+
qf_free(qi, qi->qf_curlist);
4900+
qf_update_buffer(qi, NULL);
4901+
}
4902+
4903+
if (wp != NULL && IS_LL_WINDOW(wp))
4904+
{
4905+
/* If in the location list window, then use the non-location list
4906+
* window with this location list (if present)
4907+
*/
4908+
llwin = find_win_with_ll(qi);
4909+
if (llwin != NULL)
4910+
wp = llwin;
4911+
}
4912+
48724913
qf_free_all(wp);
48734914
if (wp == NULL)
48744915
{
48754916
/* quickfix list */
48764917
qi->qf_curlist = 0;
48774918
qi->qf_listcount = 0;
48784919
}
4920+
else if (IS_LL_WINDOW(orig_wp))
4921+
{
4922+
/* If the location list window is open, then create a new empty
4923+
* location list */
4924+
qf_info_T *new_ll = ll_new_list();
4925+
orig_wp->w_llist_ref = new_ll;
4926+
if (llwin != NULL)
4927+
{
4928+
llwin->w_llist = new_ll;
4929+
new_ll->qf_refcount++;
4930+
}
4931+
}
48794932
}
48804933

48814934
/*

src/testdir/test_quickfix.vim

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,3 +1912,66 @@ func Test_vimgrep()
19121912
call XvimgrepTests('c')
19131913
call XvimgrepTests('l')
19141914
endfunc
1915+
1916+
func XfreeTests(cchar)
1917+
call s:setup_commands(a:cchar)
1918+
1919+
enew | only
1920+
1921+
" Deleting the quickfix stack should work even When the current list is
1922+
" somewhere in the middle of the stack
1923+
Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1924+
Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1925+
Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1926+
Xolder
1927+
call g:Xsetlist([], 'f')
1928+
call assert_equal(0, len(g:Xgetlist()))
1929+
1930+
" After deleting the stack, adding a new list should create a stack with a
1931+
" single list.
1932+
Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1933+
call assert_equal(1, g:Xgetlist({'all':1}).nr)
1934+
1935+
" Deleting the stack from a quickfix window should update/clear the
1936+
" quickfix/location list window.
1937+
Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1938+
Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1939+
Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1940+
Xolder
1941+
Xwindow
1942+
call g:Xsetlist([], 'f')
1943+
call assert_equal(2, winnr('$'))
1944+
call assert_equal(1, line('$'))
1945+
Xclose
1946+
1947+
" Deleting the stack from a non-quickfix window should update/clear the
1948+
" quickfix/location list window.
1949+
Xexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1950+
Xexpr ['Xfile2:20:20:Line 20', 'Xfile2:25:25:Line 25']
1951+
Xexpr ['Xfile3:30:30:Line 30', 'Xfile3:35:35:Line 35']
1952+
Xolder
1953+
Xwindow
1954+
wincmd p
1955+
call g:Xsetlist([], 'f')
1956+
call assert_equal(0, len(g:Xgetlist()))
1957+
wincmd p
1958+
call assert_equal(2, winnr('$'))
1959+
call assert_equal(1, line('$'))
1960+
1961+
" After deleting the location list stack, if the location list window is
1962+
" opened, then a new location list should be created. So opening the
1963+
" location list window again should not create a new window.
1964+
if a:cchar == 'l'
1965+
lexpr ['Xfile1:10:10:Line 10', 'Xfile1:15:15:Line 15']
1966+
wincmd p
1967+
lopen
1968+
call assert_equal(2, winnr('$'))
1969+
endif
1970+
Xclose
1971+
endfunc
1972+
1973+
" Tests for the quickifx free functionality
1974+
func Test_qf_free()
1975+
call XfreeTests('c')
1976+
call XfreeTests('l')
1977+
endfunc

src/version.c

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

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
536,
767769
/**/
768770
535,
769771
/**/

0 commit comments

Comments
 (0)