patch 8.0.1432: after ":copen" can't get the window-ID of the quickfix window
Problem: After ":copen" can't get the window-ID of the quickfix window.
(FalacerSelene)
Solution: Make it work without a quickfix list. Add a test. (Yegappan
Lakshmanan, closes #2541)
diff --git a/src/quickfix.c b/src/quickfix.c
index 8e74521..b2dabaa 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -3421,7 +3421,7 @@
/*
* Find a window displaying the quickfix/location list 'qi'
- * Searches in only the windows opened in the current tab.
+ * Only searches in the current tabpage.
*/
static win_T *
qf_find_win(qf_info_T *qi)
@@ -3430,9 +3430,8 @@
FOR_ALL_WINDOWS(win)
if (is_qf_win(win, qi))
- break;
-
- return win;
+ return win;
+ return NULL;
}
/*
@@ -4945,6 +4944,24 @@
}
/*
+ * Return the quickfix/location list window identifier in the current tabpage.
+ */
+ static int
+qf_winid(qf_info_T *qi)
+{
+ win_T *win;
+
+ /* The quickfix window can be opened even if the quickfix list is not set
+ * using ":copen". This is not true for location lists. */
+ if (qi == NULL)
+ return 0;
+ win = qf_find_win(qi);
+ if (win != NULL)
+ return win->w_id;
+ return 0;
+}
+
+/*
* Return quickfix/location list details (title) as a
* dictionary. 'what' contains the details to return. If 'list_idx' is -1,
* then current list is used. Otherwise the specified list is used.
@@ -5053,7 +5070,7 @@
if ((status == OK) && (flags & QF_GETLIST_NR))
status = dict_add_nr_str(retdict, "nr", 0L, NULL);
if ((status == OK) && (flags & QF_GETLIST_WINID))
- status = dict_add_nr_str(retdict, "winid", 0L, NULL);
+ status = dict_add_nr_str(retdict, "winid", qf_winid(qi), NULL);
if ((status == OK) && (flags & QF_GETLIST_CONTEXT))
status = dict_add_nr_str(retdict, "context", 0L, (char_u *)"");
if ((status == OK) && (flags & QF_GETLIST_ID))
@@ -5079,15 +5096,7 @@
if ((status == OK) && (flags & QF_GETLIST_NR))
status = dict_add_nr_str(retdict, "nr", qf_idx + 1, NULL);
if ((status == OK) && (flags & QF_GETLIST_WINID))
- {
- win_T *win;
- int win_id = 0;
-
- win = qf_find_win(qi);
- if (win != NULL)
- win_id = win->w_id;
- status = dict_add_nr_str(retdict, "winid", win_id, NULL);
- }
+ status = dict_add_nr_str(retdict, "winid", qf_winid(qi), NULL);
if ((status == OK) && (flags & QF_GETLIST_ITEMS))
{
list_T *l = list_alloc();