📄 quickfix.c
字号:
qf_lists[qf_curlist].qf_nonevalid = TRUE;
}
else
qf_lists[qf_curlist].qf_nonevalid = FALSE;
retval = qf_lists[qf_curlist].qf_count; /* return number of matches */
goto qf_init_ok;
}
emsg(e_readerrf);
error1:
vim_free(qfp);
error2:
qf_free(qf_curlist);
qf_listcount--;
if (qf_curlist > 0)
--qf_curlist;
qf_init_ok:
fclose(fd);
for (fmt_ptr = fmt_first; fmt_ptr != NULL; fmt_ptr = fmt_first)
{
fmt_first = fmt_ptr->next;
vim_free(fmt_ptr->fmtstr);
vim_free(fmt_ptr);
}
qf_init_end:
vim_free(namebuf);
vim_free(errmsg);
return retval;
}
/*
* jump to a quickfix line
* if dir == FORWARD go "errornr" valid entries forward
* if dir == BACKWARD go "errornr" valid entries backward
* else if "errornr" is zero, redisplay the same line
* else go to entry "errornr"
*/
void
qf_jump(dir, errornr, forceit)
int dir;
int errornr;
int forceit;
{
struct qf_line *qf_ptr;
struct qf_line *old_qf_ptr;
int qf_index;
int old_qf_index;
static char_u *e_no_more_items = (char_u *)"No more items";
char_u *err = e_no_more_items;
linenr_t i;
BUF *old_curbuf;
if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0)
{
emsg(e_quickfix);
return;
}
qf_ptr = qf_lists[qf_curlist].qf_ptr;
old_qf_ptr = qf_ptr;
qf_index = qf_lists[qf_curlist].qf_index;
old_qf_index = qf_index;
if (dir == FORWARD) /* next valid entry */
{
while (errornr--)
{
old_qf_ptr = qf_ptr;
old_qf_index = qf_index;
do
{
if (qf_index == qf_lists[qf_curlist].qf_count
|| qf_ptr->qf_next == NULL)
{
qf_ptr = old_qf_ptr;
qf_index = old_qf_index;
if (err != NULL)
{
emsg(err);
goto theend;
}
errornr = 0;
break;
}
++qf_index;
qf_ptr = qf_ptr->qf_next;
} while (!qf_lists[qf_curlist].qf_nonevalid && !qf_ptr->qf_valid);
err = NULL;
}
}
else if (dir == BACKWARD) /* previous valid entry */
{
while (errornr--)
{
old_qf_ptr = qf_ptr;
old_qf_index = qf_index;
do
{
if (qf_index == 1 || qf_ptr->qf_prev == NULL)
{
qf_ptr = old_qf_ptr;
qf_index = old_qf_index;
if (err != NULL)
{
emsg(err);
goto theend;
}
errornr = 0;
break;
}
--qf_index;
qf_ptr = qf_ptr->qf_prev;
} while (!qf_lists[qf_curlist].qf_nonevalid && !qf_ptr->qf_valid);
err = NULL;
}
}
else if (errornr != 0) /* go to specified number */
{
while (errornr < qf_index && qf_index > 1 && qf_ptr->qf_prev != NULL)
{
--qf_index;
qf_ptr = qf_ptr->qf_prev;
}
while (errornr > qf_index && qf_index < qf_lists[qf_curlist].qf_count
&& qf_ptr->qf_next != NULL)
{
++qf_index;
qf_ptr = qf_ptr->qf_next;
}
}
/*
* If there is a file name,
* read the wanted file if needed, and check autowrite etc.
*/
old_curbuf = curbuf;
if (qf_ptr->qf_fnum == 0 || buflist_getfile(qf_ptr->qf_fnum,
(linenr_t)1, GETF_SETMARK, forceit) == OK)
{
/* When not switched to another buffer, still need to set pc mark */
if (curbuf == old_curbuf)
setpcmark();
/*
* Go to line with error, unless qf_lnum is 0.
*/
i = qf_ptr->qf_lnum;
if (i > 0)
{
if (i > curbuf->b_ml.ml_line_count)
i = curbuf->b_ml.ml_line_count;
curwin->w_cursor.lnum = i;
}
if (qf_ptr->qf_col > 0)
{
curwin->w_cursor.col = qf_ptr->qf_col - 1;
adjust_cursor();
}
else
beginline(BL_WHITE | BL_FIX);
update_topline_redraw();
smsg((char_u *)"(%d of %d)%s%s: %s", qf_index,
qf_lists[qf_curlist].qf_count,
qf_ptr->qf_cleared ? (char_u *)" (line deleted)" : (char_u *)"",
qf_types(qf_ptr->qf_type, qf_ptr->qf_nr), qf_ptr->qf_text);
/*
* if the message is short, redisplay after redrawing the screen
*/
if (linetabsize(IObuff) < ((int)p_ch - 1) * Columns + sc_col)
{
keep_msg = IObuff;
keep_msg_attr = 0;
}
}
else if (qf_ptr->qf_fnum != 0)
{
/*
* Couldn't open file, so put index back where it was. This could
* happen if the file was readonly and we changed something - webb
*/
qf_ptr = old_qf_ptr;
qf_index = old_qf_index;
}
theend:
qf_lists[qf_curlist].qf_ptr = qf_ptr;
qf_lists[qf_curlist].qf_index = qf_index;
}
/*
* list all errors
*/
void
qf_list(all)
int all; /* If not :cl!, only show recognised errors */
{
BUF *buf;
char_u *fname;
struct qf_line *qfp;
int i;
if (qf_curlist >= qf_listcount || qf_lists[qf_curlist].qf_count == 0)
{
emsg(e_quickfix);
return;
}
if (qf_lists[qf_curlist].qf_nonevalid)
all = TRUE;
qfp = qf_lists[qf_curlist].qf_start;
for (i = 1; !got_int && i <= qf_lists[qf_curlist].qf_count; ++i)
{
if (qfp->qf_valid || all)
{
msg_putchar('\n');
fname = NULL;
if (qfp->qf_fnum != 0 &&
(buf = buflist_findnr(qfp->qf_fnum)) != NULL)
fname = buf->b_fname;
if (fname == NULL)
sprintf((char *)IObuff, "%2d", i);
else
sprintf((char *)IObuff, "%2d %s", i, fname);
msg_outtrans_attr(IObuff, hl_attr(HLF_D));
if (qfp->qf_lnum == 0)
IObuff[0] = NUL;
else if (qfp->qf_col == 0)
sprintf((char *)IObuff, ":%ld", qfp->qf_lnum);
else
sprintf((char *)IObuff, ":%ld, col %d",
qfp->qf_lnum, qfp->qf_col);
sprintf((char *)IObuff + STRLEN(IObuff), "%s: ",
qf_types(qfp->qf_type, qfp->qf_nr));
msg_puts_attr(IObuff, hl_attr(HLF_N));
msg_prt_line(qfp->qf_text);
out_flush(); /* show one line at a time */
}
qfp = qfp->qf_next;
ui_breakcheck();
}
}
/*
* ":colder [count]": Up in the quickfix stack.
*/
void
qf_older(count)
int count;
{
while (count--)
{
if (qf_curlist == 0)
{
EMSG("At bottom of quickfix stack");
return;
}
--qf_curlist;
}
qf_msg();
}
/*
* ":cnewer [count]": Down in the quickfix stack.
*/
void
qf_newer(count)
int count;
{
while (count--)
{
if (qf_curlist >= qf_listcount - 1)
{
EMSG("At top of quickfix stack");
return;
}
++qf_curlist;
}
qf_msg();
}
static void
qf_msg()
{
smsg((char_u *)"error list %d of %d; %d errors",
qf_curlist + 1, qf_listcount, qf_lists[qf_curlist].qf_count);
}
/*
* free the error list
*/
static void
qf_free(idx)
int idx;
{
struct qf_line *qfp;
while (qf_lists[idx].qf_count)
{
qfp = qf_lists[idx].qf_start->qf_next;
vim_free(qf_lists[idx].qf_start->qf_text);
vim_free(qf_lists[idx].qf_start);
qf_lists[idx].qf_start = qfp;
--qf_lists[idx].qf_count;
}
}
/*
* qf_mark_adjust: adjust marks
*/
void
qf_mark_adjust(line1, line2, amount, amount_after)
linenr_t line1;
linenr_t line2;
long amount;
long amount_after;
{
int i;
struct qf_line *qfp;
int idx;
for (idx = 0; idx < qf_listcount; ++idx)
if (qf_lists[idx].qf_count)
for (i = 0, qfp = qf_lists[idx].qf_start;
i < qf_lists[idx].qf_count; ++i, qfp = qfp->qf_next)
if (qfp->qf_fnum == curbuf->b_fnum)
{
if (qfp->qf_lnum >= line1 && qfp->qf_lnum <= line2)
{
if (amount == MAXLNUM)
qfp->qf_cleared = TRUE;
else
qfp->qf_lnum += amount;
}
if (amount_after && qfp->qf_lnum > line2)
qfp->qf_lnum += amount_after;
}
}
/*
* Make a nice message out of the error character and the error number:
* char number message
* e or E 0 " error"
* w or W 0 " warning"
* 0 0 ""
* other 0 " c"
* e or E n " error n"
* w or W n " warning n"
* 0 n " error n"
* other n " c n"
*/
static char_u *
qf_types(c, nr)
int c, nr;
{
static char_u buf[20];
static char_u cc[3];
char_u *p;
if (c == 'W' || c == 'w')
p = (char_u *)" warning";
else if (c == 'E' || c == 'e' || (c == 0 && nr > 0))
p = (char_u *)" error";
else if (c == 0)
p = (char_u *)"";
else
{
cc[0] = ' ';
cc[1] = c;
cc[2] = NUL;
p = cc;
}
if (nr <= 0)
return p;
sprintf((char *)buf, "%s %3d", p, nr);
return buf;
}
#endif /* QUICKFIX */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -