]> granicus.if.org Git - vim/commitdiff
patch 8.0.1112: can't get size or current index from quickfix list v8.0.1112
authorBram Moolenaar <Bram@vim.org>
Fri, 15 Sep 2017 20:43:07 +0000 (22:43 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 15 Sep 2017 20:43:07 +0000 (22:43 +0200)
Problem:    Can't get size or current index from quickfix list.
Solution:   Add "idx" and "size" options. (Yegappan Lakshmanan)

runtime/doc/eval.txt
src/quickfix.c
src/testdir/test_quickfix.vim
src/version.c

index eb4eba0c65fef11a0d070346da744f8255a9059a..1650ee804bbba52851acbff5a87cfa96f6ebebb6 100644 (file)
@@ -4642,6 +4642,7 @@ getqflist([{what}])                                       *getqflist()*
                        id      get information for the quickfix list with
                                |quickfix-ID|; zero means the id for the
                                current list or the list specifed by "nr"
+                       idx     index of the current entry in the list
                        items   quickfix list entries
                        lines   use 'errorformat' to extract items from a list
                                of lines and return the resulting entries.
@@ -4650,6 +4651,7 @@ getqflist([{what}])                                       *getqflist()*
                        nr      get information for this quickfix list; zero
                                means the current quickfix list and "$" means
                                the last quickfix list
+                       size    number of entries in the quickfix list
                        title   get the list title
                        winid   get the |window-ID| (if opened)
                        all     all of the above quickfix properties
@@ -4669,8 +4671,10 @@ getqflist([{what}])                                      *getqflist()*
                The returned dictionary contains the following entries:
                        context context information stored with |setqflist()|
                        id      quickfix list ID |quickfix-ID|
+                       idx     index of the current entry in the list
                        items   quickfix list entries
                        nr      quickfix list number
+                       size    number of entries in the quickfix list
                        title   quickfix list title text
                        winid   quickfix |window-ID| (if opened)
 
index 5ff4091d599b21defc842769830e556fc7e5c63e..39eb5b63a29628181b2ae7802971027ba8972b4b 100644 (file)
@@ -2212,8 +2212,7 @@ qf_jump(qf_info_T *qi,
     old_qf_ptr = qf_ptr;
     qf_index = qi->qf_lists[qi->qf_curlist].qf_index;
     old_qf_index = qf_index;
-    if (dir == FORWARD || dir == FORWARD_FILE ||
-       dir == BACKWARD || dir == BACKWARD_FILE)    /* next/prev valid entry */
+    if (dir != 0)    /* next/prev valid entry */
     {
        qf_ptr = get_nth_valid_entry(qi, errornr, qf_ptr, &qf_index, dir);
        if (qf_ptr == NULL)
@@ -4726,6 +4725,8 @@ enum {
     QF_GETLIST_WINID   = 0x8,
     QF_GETLIST_CONTEXT = 0x10,
     QF_GETLIST_ID      = 0x20,
+    QF_GETLIST_IDX     = 0x40,
+    QF_GETLIST_SIZE    = 0x80,
     QF_GETLIST_ALL     = 0xFF
 };
 
@@ -4882,6 +4883,12 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
     if (dict_find(what, (char_u *)"items", -1) != NULL)
        flags |= QF_GETLIST_ITEMS;
 
+    if (dict_find(what, (char_u *)"idx", -1) != NULL)
+       flags |= QF_GETLIST_IDX;
+
+    if (dict_find(what, (char_u *)"size", -1) != NULL)
+       flags |= QF_GETLIST_SIZE;
+
     if (flags & QF_GETLIST_TITLE)
     {
        char_u  *t;
@@ -4934,6 +4941,19 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
        status = dict_add_nr_str(retdict, "id", qi->qf_lists[qf_idx].qf_id,
                                                                         NULL);
 
+    if ((status == OK) && (flags & QF_GETLIST_IDX))
+    {
+       int idx = qi->qf_lists[qf_idx].qf_index;
+       if (qi->qf_lists[qf_idx].qf_count == 0)
+           /* For empty lists, qf_index is set to 1 */
+           idx = 0;
+       status = dict_add_nr_str(retdict, "idx", idx, NULL);
+    }
+
+    if ((status == OK) && (flags & QF_GETLIST_SIZE))
+       status = dict_add_nr_str(retdict, "size",
+                                       qi->qf_lists[qf_idx].qf_count, NULL);
+
     return status;
 }
 
index 671381ce1950b95d43c06360fa9c80c1fa076b36..90a51050d0cd2df7139d2c2a5844dc2325ccf237 100644 (file)
@@ -430,6 +430,19 @@ func Xtest_browse(cchar)
 
   call delete('Xqftestfile1')
   call delete('Xqftestfile2')
+
+  " Should be able to use next/prev with invalid entries
+  Xexpr ""
+  call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
+  call assert_equal(0, g:Xgetlist({'size' : 0}).size)
+  Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
+  call assert_equal(5, g:Xgetlist({'size' : 0}).size)
+  Xlast
+  call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
+  Xfirst
+  call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
+  2Xnext
+  call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
 endfunc
 
 func Test_browse()
index 854691198251973810e4d951215db9a3e6949bff..ce9d2c2499b31143acc7f6ac759d99d41c2d4398 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1112,
 /**/
     1111,
 /**/