patch 8.1.0248: duplicated quickfix code
Problem: duplicated quickfix code.
Solution: Move the code to a function.
diff --git a/src/quickfix.c b/src/quickfix.c
index 97bfb37..6108b36 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -4126,6 +4126,20 @@
}
/*
+ * Jump to the first entry if there is one.
+ */
+ static void
+qf_jump_first(qf_info_T *qi, int_u save_qfid, int forceit)
+{
+ // If autocommands changed the current list, then restore it
+ if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
+ qi->qf_curlist = qf_id2nr(qi, save_qfid);
+
+ if (qi->qf_lists[qi->qf_curlist].qf_count > 0)
+ qf_jump(qi, 0, 0, forceit);
+}
+
+/*
* Return TRUE when using ":vimgrep" for ":grep".
*/
int
@@ -4247,12 +4261,8 @@
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
curbuf->b_fname, TRUE, curbuf);
if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid))
- {
- // If autocommands changed the current list, then restore it
- if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
- qi->qf_curlist = qf_id2nr(qi, save_qfid);
- qf_jump(qi, 0, 0, FALSE); /* display first error */
- }
+ // display the first error
+ qf_jump_first(qi, save_qfid, FALSE);
cleanup:
mch_remove(fname);
@@ -4650,10 +4660,8 @@
if (res > 0 && (eap->cmdidx == CMD_cfile || eap->cmdidx == CMD_lfile)
&& qflist_valid(wp, save_qfid))
{
- // If autocommands changed the current list, then restore it
- if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
- qi->qf_curlist = qf_id2nr(qi, save_qfid);
- qf_jump(qi, 0, 0, eap->forceit); /* display first error */
+ // display the first error
+ qf_jump_first(qi, save_qfid, eap->forceit);
}
}
@@ -6361,10 +6369,8 @@
eap->cmdidx == CMD_lbuffer)
&& qflist_valid(wp, save_qfid))
{
- // If autocommands changed the current list, then restore it
- if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
- qi->qf_curlist = qf_id2nr(qi, save_qfid);
- qf_jump(qi, 0, 0, eap->forceit); /* display first error */
+ // display the first error
+ qf_jump_first(qi, save_qfid, eap->forceit);
}
}
}
@@ -6443,10 +6449,8 @@
|| eap->cmdidx == CMD_lexpr)
&& qflist_valid(wp, save_qfid))
{
- // If autocommands changed the current list, then restore it
- if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
- qi->qf_curlist = qf_id2nr(qi, save_qfid);
- qf_jump(qi, 0, 0, eap->forceit);
+ // display the first error
+ qf_jump_first(qi, save_qfid, eap->forceit);
}
}
else
diff --git a/src/version.c b/src/version.c
index 95a2e5b..cc1648f 100644
--- a/src/version.c
+++ b/src/version.c
@@ -795,6 +795,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 248,
+/**/
247,
/**/
246,