Skip to content

Commit fc2b270

Browse files
committed
patch 8.0.1112: can't get size or current index from quickfix list
Problem: Can't get size or current index from quickfix list. Solution: Add "idx" and "size" options. (Yegappan Lakshmanan)
1 parent b5e79ef commit fc2b270

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

runtime/doc/eval.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4642,6 +4642,7 @@ getqflist([{what}]) *getqflist()*
46424642
id get information for the quickfix list with
46434643
|quickfix-ID|; zero means the id for the
46444644
current list or the list specifed by "nr"
4645+
idx index of the current entry in the list
46454646
items quickfix list entries
46464647
lines use 'errorformat' to extract items from a list
46474648
of lines and return the resulting entries.
@@ -4650,6 +4651,7 @@ getqflist([{what}]) *getqflist()*
46504651
nr get information for this quickfix list; zero
46514652
means the current quickfix list and "$" means
46524653
the last quickfix list
4654+
size number of entries in the quickfix list
46534655
title get the list title
46544656
winid get the |window-ID| (if opened)
46554657
all all of the above quickfix properties
@@ -4669,8 +4671,10 @@ getqflist([{what}]) *getqflist()*
46694671
The returned dictionary contains the following entries:
46704672
context context information stored with |setqflist()|
46714673
id quickfix list ID |quickfix-ID|
4674+
idx index of the current entry in the list
46724675
items quickfix list entries
46734676
nr quickfix list number
4677+
size number of entries in the quickfix list
46744678
title quickfix list title text
46754679
winid quickfix |window-ID| (if opened)
46764680

src/quickfix.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2212,8 +2212,7 @@ qf_jump(qf_info_T *qi,
22122212
old_qf_ptr = qf_ptr;
22132213
qf_index = qi->qf_lists[qi->qf_curlist].qf_index;
22142214
old_qf_index = qf_index;
2215-
if (dir == FORWARD || dir == FORWARD_FILE ||
2216-
dir == BACKWARD || dir == BACKWARD_FILE) /* next/prev valid entry */
2215+
if (dir != 0) /* next/prev valid entry */
22172216
{
22182217
qf_ptr = get_nth_valid_entry(qi, errornr, qf_ptr, &qf_index, dir);
22192218
if (qf_ptr == NULL)
@@ -4726,6 +4725,8 @@ enum {
47264725
QF_GETLIST_WINID = 0x8,
47274726
QF_GETLIST_CONTEXT = 0x10,
47284727
QF_GETLIST_ID = 0x20,
4728+
QF_GETLIST_IDX = 0x40,
4729+
QF_GETLIST_SIZE = 0x80,
47294730
QF_GETLIST_ALL = 0xFF
47304731
};
47314732

@@ -4882,6 +4883,12 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
48824883
if (dict_find(what, (char_u *)"items", -1) != NULL)
48834884
flags |= QF_GETLIST_ITEMS;
48844885

4886+
if (dict_find(what, (char_u *)"idx", -1) != NULL)
4887+
flags |= QF_GETLIST_IDX;
4888+
4889+
if (dict_find(what, (char_u *)"size", -1) != NULL)
4890+
flags |= QF_GETLIST_SIZE;
4891+
48854892
if (flags & QF_GETLIST_TITLE)
48864893
{
48874894
char_u *t;
@@ -4934,6 +4941,19 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
49344941
status = dict_add_nr_str(retdict, "id", qi->qf_lists[qf_idx].qf_id,
49354942
NULL);
49364943

4944+
if ((status == OK) && (flags & QF_GETLIST_IDX))
4945+
{
4946+
int idx = qi->qf_lists[qf_idx].qf_index;
4947+
if (qi->qf_lists[qf_idx].qf_count == 0)
4948+
/* For empty lists, qf_index is set to 1 */
4949+
idx = 0;
4950+
status = dict_add_nr_str(retdict, "idx", idx, NULL);
4951+
}
4952+
4953+
if ((status == OK) && (flags & QF_GETLIST_SIZE))
4954+
status = dict_add_nr_str(retdict, "size",
4955+
qi->qf_lists[qf_idx].qf_count, NULL);
4956+
49374957
return status;
49384958
}
49394959

src/testdir/test_quickfix.vim

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,19 @@ func Xtest_browse(cchar)
430430

431431
call delete('Xqftestfile1')
432432
call delete('Xqftestfile2')
433+
434+
" Should be able to use next/prev with invalid entries
435+
Xexpr ""
436+
call assert_equal(0, g:Xgetlist({'idx' : 0}).idx)
437+
call assert_equal(0, g:Xgetlist({'size' : 0}).size)
438+
Xaddexpr ['foo', 'bar', 'baz', 'quux', 'shmoo']
439+
call assert_equal(5, g:Xgetlist({'size' : 0}).size)
440+
Xlast
441+
call assert_equal(5, g:Xgetlist({'idx' : 0}).idx)
442+
Xfirst
443+
call assert_equal(1, g:Xgetlist({'idx' : 0}).idx)
444+
2Xnext
445+
call assert_equal(3, g:Xgetlist({'idx' : 0}).idx)
433446
endfunc
434447

435448
func Test_browse()

src/version.c

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

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1112,
772774
/**/
773775
1111,
774776
/**/

0 commit comments

Comments
 (0)