0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.1.0720: cannot easily change the current quickfx list index

Problem:    Cannot easily change the current quickfx list index.
Solution:   Add the "idx" argument to setqflist(). (Yegappan Lakshmanan,
            closes #3701)
This commit is contained in:
Bram Moolenaar
2019-01-11 14:50:06 +01:00
parent 870ba5f6dc
commit 5b69c22fd2
5 changed files with 169 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
*eval.txt* For Vim version 8.1. Last change: 2019 Jan 06 *eval.txt* For Vim version 8.1. Last change: 2019 Jan 11
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3979,7 +3979,7 @@ feedkeys({string} [, {mode}]) *feedkeys()*
stuck, waiting for a character to be typed before the stuck, waiting for a character to be typed before the
script continues. script continues.
Note that if you manage to call feedkeys() while Note that if you manage to call feedkeys() while
executing commands, thus calling it recursively, the executing commands, thus calling it recursively, then
all typehead will be consumed by the last call. all typehead will be consumed by the last call.
'!' When used with 'x' will not end Insert mode. Can be '!' When used with 'x' will not end Insert mode. Can be
used in a test when a timer is set to exit Insert mode used in a test when a timer is set to exit Insert mode
@@ -4794,7 +4794,7 @@ getloclist({nr} [, {what}]) *getloclist()*
If {what} contains 'filewinid', then returns the id of the If {what} contains 'filewinid', then returns the id of the
window used to display files from the location list. This window used to display files from the location list. This
field is applicable only when called from a location list field is applicable only when called from a location list
window. window. See |location-list-file-window| for more details.
getmatches() *getmatches()* getmatches() *getmatches()*
Returns a |List| with all matches previously defined by Returns a |List| with all matches previously defined by
@@ -4885,7 +4885,9 @@ getqflist([{what}]) *getqflist()*
id get information for the quickfix list with id get information for the quickfix list with
|quickfix-ID|; zero means the id for the |quickfix-ID|; zero means the id for the
current list or the list specified by "nr" current list or the list specified by "nr"
idx index of the current entry in the list idx index of the current entry in the quickfix
list specified by 'id' or 'nr'.
See |quickfix-index|
items quickfix list entries items quickfix list entries
lines parse a list of lines using 'efm' and return lines parse a list of lines using 'efm' and return
the resulting entries. Only a |List| type is the resulting entries. Only a |List| type is
@@ -6708,10 +6710,10 @@ prop_add({lnum}, {col}, {props})
for a property that does not continue in for a property that does not continue in
another line; can be zero another line; can be zero
end_lnum line number for the end of text end_lnum line number for the end of text
end_col column just after the text; not used when "length" end_col column just after the text; not used when
is present; when {col} and "end_col" are "length" is present; when {col} and "end_col"
equal, and "end_lnum" is omitted or equal to are equal, and "end_lnum" is omitted or equal
{lnum}, this is a zero-width text property to {lnum}, this is a zero-width text property
bufnr buffer to add the property to; when omitted bufnr buffer to add the property to; when omitted
the current buffer is used the current buffer is used
id user defined ID for the property; when omitted id user defined ID for the property; when omitted
@@ -6758,7 +6760,7 @@ prop_find({props} [, {direction}])
start position with "lnum" and "col" start position with "lnum" and "col"
must be given; when omitted the must be given; when omitted the
current buffer is used current buffer is used
lnum" start in this line (when omitted start lnum start in this line (when omitted start
at the cursor) at the cursor)
col start at this column (when omitted col start at this column (when omitted
and "lnum" is given: use column 1, and "lnum" is given: use column 1,
@@ -7701,16 +7703,22 @@ setqflist({list} [, {action} [, {what}]]) *setqflist()*
efm errorformat to use when parsing text from efm errorformat to use when parsing text from
"lines". If this is not present, then the "lines". If this is not present, then the
'errorformat' option value is used. 'errorformat' option value is used.
See |quickfix-parse|
id quickfix list identifier |quickfix-ID| id quickfix list identifier |quickfix-ID|
idx index of the current entry in the quickfix
list specified by 'id' or 'nr'. If set to '$',
then the last entry in the list is set as the
current entry. See |quickfix-index|
items list of quickfix entries. Same as the {list} items list of quickfix entries. Same as the {list}
argument. argument.
lines use 'errorformat' to parse a list of lines and lines use 'errorformat' to parse a list of lines and
add the resulting entries to the quickfix list add the resulting entries to the quickfix list
{nr} or {id}. Only a |List| value is supported. {nr} or {id}. Only a |List| value is supported.
See |quickfix-parse|
nr list number in the quickfix stack; zero nr list number in the quickfix stack; zero
means the current quickfix list and "$" means means the current quickfix list and "$" means
the last quickfix list the last quickfix list.
title quickfix list title text title quickfix list title text. See |quickfix-title|
Unsupported keys in {what} are ignored. Unsupported keys in {what} are ignored.
If the "nr" item is not present, then the current quickfix list If the "nr" item is not present, then the current quickfix list
is modified. When creating a new quickfix list, "nr" can be is modified. When creating a new quickfix list, "nr" can be
@@ -8026,7 +8034,7 @@ sign_place({id}, {group}, {name}, {expr} [, {dict}])
the sign group name. To use the global sign group, use an the sign group name. To use the global sign group, use an
empty string. {group} functions as a namespace for {id}, thus empty string. {group} functions as a namespace for {id}, thus
two groups can use the same IDs. Refer to |sign-identifier| two groups can use the same IDs. Refer to |sign-identifier|
for more information. and |sign-group| for more information.
{name} refers to a defined sign. {name} refers to a defined sign.
{expr} refers to a buffer name or number. For the accepted {expr} refers to a buffer name or number. For the accepted
@@ -10091,9 +10099,9 @@ vim_starting True while initial source'ing takes place. |startup|
*vim_starting* *vim_starting*
viminfo Compiled with viminfo support. viminfo Compiled with viminfo support.
virtualedit Compiled with 'virtualedit' option. virtualedit Compiled with 'virtualedit' option.
visual Compiled with Visual mode. visual Compiled with Visual mode. (always true)
visualextra Compiled with extra Visual mode commands. visualextra Compiled with extra Visual mode commands. (always
|blockwise-operators|. true) |blockwise-operators|.
vms VMS version of Vim. vms VMS version of Vim.
vreplace Compiled with |gR| and |gr| commands. vreplace Compiled with |gR| and |gr| commands.
vtp Compiled for vcon support |+vtp| (check vcon to find vtp Compiled for vcon support |+vtp| (check vcon to find

View File

@@ -1,4 +1,4 @@
*quickfix.txt* For Vim version 8.1. Last change: 2018 Dec 27 *quickfix.txt* For Vim version 8.1. Last change: 2019 Jan 09
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -56,6 +56,7 @@ A location list is a window-local quickfix list. You get one after commands
like `:lvimgrep`, `:lgrep`, `:lhelpgrep`, `:lmake`, etc., which create a like `:lvimgrep`, `:lgrep`, `:lhelpgrep`, `:lmake`, etc., which create a
location list instead of a quickfix list as the corresponding `:vimgrep`, location list instead of a quickfix list as the corresponding `:vimgrep`,
`:grep`, `:helpgrep`, `:make` do. `:grep`, `:helpgrep`, `:make` do.
*location-list-file-window*
A location list is associated with a window and each window can have a A location list is associated with a window and each window can have a
separate location list. A location list can be associated with only one separate location list. A location list can be associated with only one
window. The location list is independent of the quickfix list. window. The location list is independent of the quickfix list.
@@ -363,6 +364,23 @@ modify the title of a quickfix and location list respectively. Examples: >
echo getqflist({'title' : 1}) echo getqflist({'title' : 1})
call setloclist(3, [], 'a', {'title' : 'Cmd output'}) call setloclist(3, [], 'a', {'title' : 'Cmd output'})
echo getloclist(3, {'title' : 1}) echo getloclist(3, {'title' : 1})
<
*quickfix-index*
When you jump to a quickfix/location list entry using any of the quickfix
commands (e.g. |cc|, |cnext|, |cprev|, etc.), that entry becomes the currently
selected entry. The index of the currently selected entry in a
quickfix/location list can be obtained using the getqflist()/getloclist()
functions. Examples: >
echo getqflist({'idx' : 0}).idx
echo getqflist({'id' : qfid, 'idx' : 0}).idx
echo getloclist(2, {'idx' : 0}).idx
<
For a new quickfix list, the first entry is selected and the index is 1. Any
entry in any quickfix/location list can be set as the currently selected entry
using the setqflist() function. Examples: >
call setqflist([], 'a', {'idx' : 12})
call setqflist([], 'a', {'id' : qfid, 'idx' : 7})
call setloclist(1, [], 'a', {'idx' : 7})
< <
*quickfix-size* *quickfix-size*
You can get the number of entries (size) in a quickfix and a location list You can get the number of entries (size) in a quickfix and a location list
@@ -657,6 +675,9 @@ using these functions are below:
" get the location list window id of the third window " get the location list window id of the third window
:echo getloclist(3, {'winid' : 0}).winid :echo getloclist(3, {'winid' : 0}).winid
" get the file window id of a location list window (winnr: 4)
:echo getloclist(4, {'filewinid' : 0}).filewinid
< <
*setqflist-examples* *setqflist-examples*
The |setqflist()| and |setloclist()| functions can be used to set the various The |setqflist()| and |setloclist()| functions can be used to set the various
@@ -671,6 +692,9 @@ using these functions are below:
" set the title of the current quickfix list " set the title of the current quickfix list
:call setqflist([], 'a', {'title' : 'Mytitle'}) :call setqflist([], 'a', {'title' : 'Mytitle'})
" change the current entry in the list specified by an identifier
:call setqflist([], 'a', {'id' : qfid, 'idx' : 10})
" set the context of a quickfix list specified by an identifier " set the context of a quickfix list specified by an identifier
:call setqflist([], 'a', {'id' : qfid, 'context' : {'val' : 100}}) :call setqflist([], 'a', {'id' : qfid, 'context' : {'val' : 100}})

View File

@@ -3266,13 +3266,7 @@ qf_jump_to_buffer(
} }
/* /*
* Jump to a quickfix line. * Jump to a quickfix line and try to use an existing window.
* If dir == FORWARD go "errornr" valid entries forward.
* If dir == BACKWARD go "errornr" valid entries backward.
* If dir == FORWARD_FILE go "errornr" valid entries files backward.
* If dir == BACKWARD_FILE go "errornr" valid entries files backward
* else if "errornr" is zero, redisplay the same line
* else go to entry "errornr".
*/ */
void void
qf_jump(qf_info_T *qi, qf_jump(qf_info_T *qi,
@@ -3284,7 +3278,14 @@ qf_jump(qf_info_T *qi,
} }
/* /*
* As qf_info(). * Jump to a quickfix line.
* If dir == 0 go to entry "errornr".
* If dir == FORWARD go "errornr" valid entries forward.
* If dir == BACKWARD go "errornr" valid entries backward.
* If dir == FORWARD_FILE go "errornr" valid entries files backward.
* If dir == BACKWARD_FILE go "errornr" valid entries files backward
* else if "errornr" is zero, redisplay the same line
* If 'forceit' is TRUE, then can discard changes to the current buffer.
* If 'newwin' is TRUE, then open the file in a new window. * If 'newwin' is TRUE, then open the file in a new window.
*/ */
void void
@@ -3687,7 +3688,7 @@ qf_history(exarg_T *eap)
if (is_loclist_cmd(eap->cmdidx)) if (is_loclist_cmd(eap->cmdidx))
qi = GET_LOC_LIST(curwin); qi = GET_LOC_LIST(curwin);
if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) if (qf_stack_empty(qi))
MSG(_("No entries")); MSG(_("No entries"));
else else
for (i = 0; i < qi->qf_listcount; ++i) for (i = 0; i < qi->qf_listcount; ++i)
@@ -6548,6 +6549,50 @@ qf_setprop_context(qf_list_T *qfl, dictitem_T *di)
return OK; return OK;
} }
/*
* Set the current index in the specified quickfix list
*/
static int
qf_setprop_curidx(qf_info_T *qi, qf_list_T *qfl, dictitem_T *di)
{
int denote = FALSE;
int newidx;
int old_qfidx;
qfline_T *qf_ptr;
// If the specified index is '$', then use the last entry
if (di->di_tv.v_type == VAR_STRING
&& di->di_tv.vval.v_string != NULL
&& STRCMP(di->di_tv.vval.v_string, "$") == 0)
newidx = qfl->qf_count;
else
{
// Otherwise use the specified index
newidx = tv_get_number_chk(&di->di_tv, &denote);
if (denote)
return FAIL;
}
if (newidx < 1) // sanity check
return FAIL;
if (newidx > qfl->qf_count)
newidx = qfl->qf_count;
old_qfidx = qfl->qf_index;
qf_ptr = get_nth_entry(qfl, newidx, &newidx);
if (qf_ptr == NULL)
return FAIL;
qfl->qf_ptr = qf_ptr;
qfl->qf_index = newidx;
// If the current list is modified and it is displayed in the quickfix
// window, then Update it.
if (qi->qf_lists[qi->qf_curlist].qf_id == qfl->qf_id)
qf_win_pos_update(qi, old_qfidx);
return OK;
}
/* /*
* Set quickfix/location list properties (title, items, context). * Set quickfix/location list properties (title, items, context).
* Also used to add items from parsing a list of lines. * Also used to add items from parsing a list of lines.
@@ -6585,6 +6630,8 @@ qf_set_properties(qf_info_T *qi, dict_T *what, int action, char_u *title)
retval = qf_setprop_items_from_lines(qi, qf_idx, what, di, action); retval = qf_setprop_items_from_lines(qi, qf_idx, what, di, action);
if ((di = dict_find(what, (char_u *)"context", -1)) != NULL) if ((di = dict_find(what, (char_u *)"context", -1)) != NULL)
retval = qf_setprop_context(qfl, di); retval = qf_setprop_context(qfl, di);
if ((di = dict_find(what, (char_u *)"idx", -1)) != NULL)
retval = qf_setprop_curidx(qi, qfl, di);
if (retval == OK) if (retval == OK)
qf_list_changed(qfl); qf_list_changed(qfl);

View File

@@ -1811,6 +1811,13 @@ func HistoryTest(cchar)
call g:Xsetlist([], 'f') call g:Xsetlist([], 'f')
let l = split(execute(a:cchar . 'hist'), "\n") let l = split(execute(a:cchar . 'hist'), "\n")
call assert_equal('No entries', l[0]) call assert_equal('No entries', l[0])
" An empty list should still show the stack history
call g:Xsetlist([])
let res = split(execute(a:cchar . 'hist'), "\n")
call assert_equal('> error list 1 of 1; 0 ' . common, res[0])
call g:Xsetlist([], 'f')
endfunc endfunc
func Test_history() func Test_history()
@@ -2068,6 +2075,56 @@ func Test_qf_property()
call Xproperty_tests('l') call Xproperty_tests('l')
endfunc endfunc
" Test for setting the current index in the location/quickfix list
func Xtest_setqfidx(cchar)
call s:setup_commands(a:cchar)
Xgetexpr "F1:10:1:Line1\nF2:20:2:Line2\nF3:30:3:Line3"
Xgetexpr "F4:10:1:Line1\nF5:20:2:Line2\nF6:30:3:Line3"
Xgetexpr "F7:10:1:Line1\nF8:20:2:Line2\nF9:30:3:Line3"
call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 2})
call g:Xsetlist([], 'a', {'nr' : 2, 'idx' : 2})
call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 3})
Xolder 2
Xopen
call assert_equal(3, line('.'))
Xnewer
call assert_equal(2, line('.'))
Xnewer
call assert_equal(2, line('.'))
" Update the current index with the quickfix window open
wincmd w
call g:Xsetlist([], 'a', {'nr' : 3, 'idx' : 3})
Xopen
call assert_equal(3, line('.'))
Xclose
" Set the current index to the last entry
call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : '$'})
call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
" A large value should set the index to the last index
call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 1})
call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 999})
call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
" Invalid index values
call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : -1})
call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 0})
call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
call g:Xsetlist([], 'a', {'nr' : 1, 'idx' : 'xx'})
call assert_equal(3, g:Xgetlist({'nr' : 1, 'idx' : 0}).idx)
call assert_fails("call g:Xsetlist([], 'a', {'nr':1, 'idx':[]})", 'E745:')
call g:Xsetlist([], 'f')
new | only
endfunc
func Test_setqfidx()
call Xtest_setqfidx('c')
call Xtest_setqfidx('l')
endfunc
" Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands " Tests for the QuickFixCmdPre/QuickFixCmdPost autocommands
func QfAutoCmdHandler(loc, cmd) func QfAutoCmdHandler(loc, cmd)
call add(g:acmds, a:loc . a:cmd) call add(g:acmds, a:loc . a:cmd)

View File

@@ -795,6 +795,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
720,
/**/ /**/
719, 719,
/**/ /**/