Merge #11007 from janlazo/vim-8.0.1772

vim-patch:8.0.1772,8.1.{248,259,261,267}
This commit is contained in:
Justin M. Keyes
2019-09-13 14:38:16 -07:00
committed by GitHub
2 changed files with 82 additions and 35 deletions

View File

@@ -728,6 +728,15 @@ static int qf_get_nextline(qfstate_T *state)
return QF_OK; return QF_OK;
} }
// Returns true if the specified quickfix/location list is empty.
static bool qf_list_empty(const qf_info_T *qi, int qf_idx)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
if (qi == NULL || qf_idx < 0 || qf_idx >= LISTCOUNT) {
return true;
}
return qi->qf_lists[qf_idx].qf_count <= 0;
}
/// Parse a line and get the quickfix fields. /// Parse a line and get the quickfix fields.
/// Return the QF_ status. /// Return the QF_ status.
@@ -2209,7 +2218,7 @@ static int qf_jump_edit_buffer(qf_info_T *qi, qfline_T *qf_ptr, int forceit,
// set b_p_ro flag). // set b_p_ro flag).
if (!can_abandon(curbuf, forceit)) { if (!can_abandon(curbuf, forceit)) {
no_write_message(); no_write_message();
retval = false; retval = FAIL;
} else { } else {
retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1, retval = do_ecmd(qf_ptr->qf_fnum, NULL, NULL, NULL, (linenr_T)1,
ECMD_HIDE + ECMD_SET_HELP, ECMD_HIDE + ECMD_SET_HELP,
@@ -2242,7 +2251,7 @@ static int qf_jump_edit_buffer(qf_info_T *qi, qfline_T *qf_ptr, int forceit,
} }
if (*abort) { if (*abort) {
retval = false; retval = FAIL;
} }
} }
@@ -2906,8 +2915,7 @@ void qf_view_result(bool split)
if (IS_LL_WINDOW(curwin)) { if (IS_LL_WINDOW(curwin)) {
qi = GET_LOC_LIST(curwin); qi = GET_LOC_LIST(curwin);
} }
if (qi == NULL if (qf_list_empty(qi, qi->qf_curlist)) {
|| qi->qf_lists[qi->qf_curlist].qf_count == 0) {
EMSG(_(e_quickfix)); EMSG(_(e_quickfix));
return; return;
} }
@@ -3448,6 +3456,38 @@ static int qf_id2nr(const qf_info_T *const qi, const unsigned qfid)
return INVALID_QFIDX; return INVALID_QFIDX;
} }
// If the current list is not "save_qfid" and we can find the list with that ID
// then make it the current list.
// This is used when autocommands may have changed the current list.
// Returns OK if successfully restored the list. Returns FAIL if the list with
// the specified identifier (save_qfid) is not found in the stack.
static int qf_restore_list(qf_info_T *qi, unsigned save_qfid)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT
{
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) {
const int curlist = qf_id2nr(qi, save_qfid);
if (curlist < 0) {
// list is not present
return FAIL;
}
qi->qf_curlist = curlist;
}
return OK;
}
// Jump to the first entry if there is one.
static void qf_jump_first(qf_info_T *qi, unsigned save_qfid, int forceit)
FUNC_ATTR_NONNULL_ALL
{
if (qf_restore_list(qi, save_qfid) == FAIL) {
return;
}
// Autocommands might have cleared the list, check for that
if (!qf_list_empty(qi, qi->qf_curlist)) {
qf_jump(qi, 0, 0, forceit);
}
}
/* /*
* Return TRUE when using ":vimgrep" for ":grep". * Return TRUE when using ":vimgrep" for ":grep".
*/ */
@@ -3549,11 +3589,8 @@ void ex_make(exarg_T *eap)
curbuf); curbuf);
} }
if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid)) { if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid)) {
// If autocommands changed the current list, then restore it. // display the first error
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { qf_jump_first(qi, save_qfid, false);
qi->qf_curlist = qf_id2nr(qi, save_qfid);
}
qf_jump(qi, 0, 0, false); // display first error
} }
cleanup: cleanup:
@@ -3919,11 +3956,8 @@ void ex_cfile(exarg_T *eap)
// list. // list.
if (res > 0 && (eap->cmdidx == CMD_cfile || eap->cmdidx == CMD_lfile) if (res > 0 && (eap->cmdidx == CMD_cfile || eap->cmdidx == CMD_lfile)
&& qflist_valid(wp, save_qfid)) { && qflist_valid(wp, save_qfid)) {
// If autocommands changed the current list, then restore it // display the first error
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { qf_jump_first(qi, save_qfid, eap->forceit);
qi->qf_curlist = qf_id2nr(qi, save_qfid);
}
qf_jump(qi, 0, 0, eap->forceit); // display first error
} }
} }
@@ -4022,10 +4056,8 @@ static bool vgr_qflist_valid(win_T *wp, qf_info_T *qi, unsigned qfid,
return true; return true;
} }
} }
if (qi->qf_lists[qi->qf_curlist].qf_id != qfid) { if (qf_restore_list(qi, qfid) == FAIL) {
// Autocommands changed the quickfix list. Find the one we were using return false;
// and restore it.
qi->qf_curlist = qf_id2nr(qi, qfid);
} }
return true; return true;
@@ -4322,9 +4354,8 @@ void ex_vimgrep(exarg_T *eap)
goto theend; goto theend;
} }
// If autocommands changed the current list, then restore it. if (qf_restore_list(qi, save_qfid) == FAIL) {
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { goto theend;
qi->qf_curlist = qf_id2nr(qi, save_qfid);
} }
/* Jump to first match. */ /* Jump to first match. */
@@ -4532,7 +4563,7 @@ int get_errorlist(const qf_info_T *qi_arg, win_T *wp, int qf_idx, list_T *list)
} }
} }
if (qf_idx == -1) { if (qf_idx == INVALID_QFIDX) {
qf_idx = qi->qf_curlist; qf_idx = qi->qf_curlist;
} }
@@ -4625,9 +4656,7 @@ static int qf_get_list_from_lines(dict_T *what, dictitem_T *di, dict_T *retdict)
} }
list_T *l = tv_list_alloc(kListLenMayKnow); list_T *l = tv_list_alloc(kListLenMayKnow);
qf_info_T *qi = xmalloc(sizeof(*qi)); qf_info_T *const qi = ll_new_list();
memset(qi, 0, sizeof(*qi));
qi->qf_refcount++;
if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat, if (qf_init_ext(qi, 0, NULL, NULL, &di->di_tv, errorformat,
true, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) { true, (linenr_T)0, (linenr_T)0, NULL, NULL) > 0) {
@@ -5421,11 +5450,8 @@ void ex_cbuffer(exarg_T *eap)
// free the list. // free the list.
if (res > 0 && (eap->cmdidx == CMD_cbuffer || eap->cmdidx == CMD_lbuffer) if (res > 0 && (eap->cmdidx == CMD_cbuffer || eap->cmdidx == CMD_lbuffer)
&& qflist_valid(wp, save_qfid)) { && qflist_valid(wp, save_qfid)) {
// If autocommands changed the current list, then restore it. // display the first error
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { qf_jump_first(qi, save_qfid, eap->forceit);
qi->qf_curlist = qf_id2nr(qi, save_qfid);
}
qf_jump(qi, 0, 0, eap->forceit); // display first error
} }
} }
} }
@@ -5503,11 +5529,8 @@ void ex_cexpr(exarg_T *eap)
if (res > 0 if (res > 0
&& (eap->cmdidx == CMD_cexpr || eap->cmdidx == CMD_lexpr) && (eap->cmdidx == CMD_cexpr || eap->cmdidx == CMD_lexpr)
&& qflist_valid(wp, save_qfid)) { && qflist_valid(wp, save_qfid)) {
// If autocommands changed the current list, then restore it. // display the first error
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid) { qf_jump_first(qi, save_qfid, eap->forceit);
qi->qf_curlist = qf_id2nr(qi, save_qfid);
}
qf_jump(qi, 0, 0, eap->forceit);
} }
} else { } else {
EMSG(_("E777: String or List expected")); EMSG(_("E777: String or List expected"));

View File

@@ -3515,6 +3515,30 @@ func Xautocmd_changelist(cchar)
call assert_equal(5, line('.')) call assert_equal(5, line('.'))
autocmd! QuickFixCmdPost autocmd! QuickFixCmdPost
" Test for autocommands clearing the quickfix list before jumping to the
" first error. This should not result in an error
autocmd QuickFixCmdPost * call g:Xsetlist([], 'r')
let v:errmsg = ''
" Test for cfile/lfile
Xfile Xerr
call assert_true(v:errmsg !~# 'E42:')
" Test for cbuffer/lbuffer
edit Xerr
Xbuffer
call assert_true(v:errmsg !~# 'E42:')
" Test for cexpr/lexpr
Xexpr 'Xtestfile2:4:Line4'
call assert_true(v:errmsg !~# 'E42:')
" Test for grep/lgrep
" The grepprg may not be set on non-Unix systems
if has('unix')
silent Xgrep Line5 Xtestfile2
call assert_true(v:errmsg !~# 'E42:')
endif
" Test for vimgrep/lvimgrep
call assert_fails('silent Xvimgrep Line5 Xtestfile2', 'E480:')
autocmd! QuickFixCmdPost
call delete('Xerr') call delete('Xerr')
call delete('Xtestfile1') call delete('Xtestfile1')
call delete('Xtestfile2') call delete('Xtestfile2')