mirror of
https://github.com/neovim/neovim.git
synced 2025-10-06 18:06:30 +00:00
vim-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 vim/vim#3701)
5b69c22fd2
This commit is contained in:
@@ -2936,19 +2936,20 @@ static int qf_jump_to_buffer(qf_info_T *qi, int qf_index, qfline_T *qf_ptr,
|
||||
return retval;
|
||||
}
|
||||
|
||||
/// Jump to a quickfix line.
|
||||
/// 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".
|
||||
/// Jump to a quickfix line and try to use an existing window.
|
||||
void qf_jump(qf_info_T *qi, int dir, int errornr, int forceit)
|
||||
{
|
||||
qf_jump_newwin(qi, dir, errornr, forceit, false);
|
||||
}
|
||||
|
||||
// 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.
|
||||
static void qf_jump_newwin(qf_info_T *qi, int dir, int errornr, int forceit,
|
||||
bool newwin)
|
||||
@@ -3297,7 +3298,7 @@ void qf_history(exarg_T *eap)
|
||||
qf_info_T *qi = qf_cmd_get_stack(eap, false);
|
||||
int i;
|
||||
|
||||
if (qf_stack_empty(qi) || qf_list_empty(qf_get_curlist(qi))) {
|
||||
if (qf_stack_empty(qi)) {
|
||||
MSG(_("No entries"));
|
||||
} else {
|
||||
for (i = 0; i < qi->qf_listcount; i++) {
|
||||
@@ -6134,6 +6135,49 @@ static int qf_setprop_context(qf_list_T *qfl, dictitem_T *di)
|
||||
return OK;
|
||||
}
|
||||
|
||||
// Set the current index in the specified quickfix list
|
||||
static int qf_setprop_curidx(qf_info_T *qi, qf_list_T *qfl,
|
||||
const dictitem_T *di)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
int newidx;
|
||||
|
||||
// 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
|
||||
bool denote = false;
|
||||
newidx = (int)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;
|
||||
}
|
||||
const int old_qfidx = qfl->qf_index;
|
||||
qfline_T *const 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).
|
||||
/// Also used to add items from parsing a list of lines.
|
||||
/// Used by the setqflist() and setloclist() Vim script functions.
|
||||
@@ -6169,6 +6213,9 @@ static int qf_set_properties(qf_info_T *qi, const dict_T *what, int action,
|
||||
if ((di = tv_dict_find(what, S_LEN("context"))) != NULL) {
|
||||
retval = qf_setprop_context(qfl, di);
|
||||
}
|
||||
if ((di = tv_dict_find(what, S_LEN("idx"))) != NULL) {
|
||||
retval = qf_setprop_curidx(qi, qfl, di);
|
||||
}
|
||||
|
||||
if (retval == OK) {
|
||||
qf_list_changed(qfl);
|
||||
|
@@ -1916,6 +1916,13 @@ func HistoryTest(cchar)
|
||||
call g:Xsetlist([], 'f')
|
||||
let l = split(execute(a:cchar . 'hist'), "\n")
|
||||
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
|
||||
|
||||
func Test_history()
|
||||
@@ -2173,6 +2180,56 @@ func Test_qf_property()
|
||||
call Xproperty_tests('l')
|
||||
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
|
||||
func QfAutoCmdHandler(loc, cmd)
|
||||
call add(g:acmds, a:loc . a:cmd)
|
||||
|
Reference in New Issue
Block a user