]> granicus.if.org Git - vim/commitdiff
patch 8.0.1432: after ":copen" can't get the window-ID of the quickfix window v8.0.1432
authorBram Moolenaar <Bram@vim.org>
Sat, 27 Jan 2018 10:52:13 +0000 (11:52 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 27 Jan 2018 10:52:13 +0000 (11:52 +0100)
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)

src/quickfix.c
src/testdir/test_quickfix.vim
src/version.c

index 8e745213ac624fe8ecebdbf78eeeae5e4d12bed7..b2dabaaacd0d48f4b14b95d0420451d03af64dc8 100644 (file)
@@ -3421,7 +3421,7 @@ is_qf_win(win_T *win, qf_info_T *qi)
 
 /*
  * 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 @@ qf_find_win(qf_info_T *qi)
 
     FOR_ALL_WINDOWS(win)
        if (is_qf_win(win, qi))
-           break;
-
-    return win;
+           return win;
+    return NULL;
 }
 
 /*
@@ -4944,6 +4943,24 @@ qf_id2nr(qf_info_T *qi, int_u qfid)
     return -1;
 }
 
+/*
+ * 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,
@@ -5053,7 +5070,7 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
        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 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
     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();
index fb78f6983af4ae8d6c415c54bae668d47f0e7edb..71aa7d5b192c7f5f49258d4be3521698dab907ce 100644 (file)
@@ -2906,6 +2906,12 @@ func Xgetlist_empty_tests(cchar)
   call assert_equal(0, g:Xgetlist({'changedtick' : 0}).changedtick)
   call assert_equal({'context' : '', 'id' : 0, 'idx' : 0, 'items' : [], 'nr' : 0, 'size' : 0, 'title' : '', 'winid' : 0, 'changedtick': 0}, g:Xgetlist({'all' : 0}))
 
+  " Quickfix window with empty stack
+  silent! Xopen
+  let qfwinid = (a:cchar == 'c') ? win_getid() : 0
+  call assert_equal(qfwinid, g:Xgetlist({'winid' : 0}).winid)
+  Xclose
+
   " Empty quickfix list
   Xexpr ""
   call assert_equal('', g:Xgetlist({'context' : 0}).context)
index 6362b55279e7368aab8b2da120dc3bdb33cb14c5..2a3460edce1a7066f04e34162bf8e76c41acef72 100644 (file)
@@ -771,6 +771,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1432,
 /**/
     1431,
 /**/