forked from aniani/vim
patch 8.2.2813: cannot grep using fuzzy matching
Problem: Cannot grep using fuzzy matching. Solution: Add the "f" flag to :vimgrep. (Yegappan Lakshmanan, closes #8152)
This commit is contained in:
committed by
Bram Moolenaar
parent
5930ddcd25
commit
bb01a1ef3a
113
src/quickfix.c
113
src/quickfix.c
@@ -5912,6 +5912,7 @@ vgr_match_buflines(
|
||||
qf_list_T *qfl,
|
||||
char_u *fname,
|
||||
buf_T *buf,
|
||||
char_u *spat,
|
||||
regmmatch_T *regmatch,
|
||||
long *tomatch,
|
||||
int duplicate_name,
|
||||
@@ -5920,45 +5921,91 @@ vgr_match_buflines(
|
||||
int found_match = FALSE;
|
||||
long lnum;
|
||||
colnr_T col;
|
||||
int pat_len = STRLEN(spat);
|
||||
|
||||
for (lnum = 1; lnum <= buf->b_ml.ml_line_count && *tomatch > 0; ++lnum)
|
||||
{
|
||||
col = 0;
|
||||
while (vim_regexec_multi(regmatch, curwin, buf, lnum,
|
||||
col, NULL, NULL) > 0)
|
||||
if (!(flags & VGR_FUZZY))
|
||||
{
|
||||
// Pass the buffer number so that it gets used even for a
|
||||
// dummy buffer, unless duplicate_name is set, then the
|
||||
// buffer will be wiped out below.
|
||||
if (qf_add_entry(qfl,
|
||||
NULL, // dir
|
||||
fname,
|
||||
NULL,
|
||||
duplicate_name ? 0 : buf->b_fnum,
|
||||
ml_get_buf(buf,
|
||||
regmatch->startpos[0].lnum + lnum, FALSE),
|
||||
regmatch->startpos[0].lnum + lnum,
|
||||
regmatch->startpos[0].col + 1,
|
||||
FALSE, // vis_col
|
||||
NULL, // search pattern
|
||||
0, // nr
|
||||
0, // type
|
||||
TRUE // valid
|
||||
) == QF_FAIL)
|
||||
// Regular expression match
|
||||
while (vim_regexec_multi(regmatch, curwin, buf, lnum,
|
||||
col, NULL, NULL) > 0)
|
||||
{
|
||||
got_int = TRUE;
|
||||
break;
|
||||
// Pass the buffer number so that it gets used even for a
|
||||
// dummy buffer, unless duplicate_name is set, then the
|
||||
// buffer will be wiped out below.
|
||||
if (qf_add_entry(qfl,
|
||||
NULL, // dir
|
||||
fname,
|
||||
NULL,
|
||||
duplicate_name ? 0 : buf->b_fnum,
|
||||
ml_get_buf(buf,
|
||||
regmatch->startpos[0].lnum + lnum, FALSE),
|
||||
regmatch->startpos[0].lnum + lnum,
|
||||
regmatch->startpos[0].col + 1,
|
||||
FALSE, // vis_col
|
||||
NULL, // search pattern
|
||||
0, // nr
|
||||
0, // type
|
||||
TRUE // valid
|
||||
) == QF_FAIL)
|
||||
{
|
||||
got_int = TRUE;
|
||||
break;
|
||||
}
|
||||
found_match = TRUE;
|
||||
if (--*tomatch == 0)
|
||||
break;
|
||||
if ((flags & VGR_GLOBAL) == 0
|
||||
|| regmatch->endpos[0].lnum > 0)
|
||||
break;
|
||||
col = regmatch->endpos[0].col
|
||||
+ (col == regmatch->endpos[0].col);
|
||||
if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE)))
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char_u *str = ml_get_buf(buf, lnum, FALSE);
|
||||
int score;
|
||||
int_u matches[MAX_FUZZY_MATCHES];
|
||||
int_u sz = sizeof(matches) / sizeof(matches[0]);
|
||||
|
||||
// Fuzzy string match
|
||||
while (fuzzy_match(str + col, spat, FALSE, &score, matches, sz) > 0)
|
||||
{
|
||||
// Pass the buffer number so that it gets used even for a
|
||||
// dummy buffer, unless duplicate_name is set, then the
|
||||
// buffer will be wiped out below.
|
||||
if (qf_add_entry(qfl,
|
||||
NULL, // dir
|
||||
fname,
|
||||
NULL,
|
||||
duplicate_name ? 0 : buf->b_fnum,
|
||||
str,
|
||||
lnum,
|
||||
matches[0] + col + 1,
|
||||
FALSE, // vis_col
|
||||
NULL, // search pattern
|
||||
0, // nr
|
||||
0, // type
|
||||
TRUE // valid
|
||||
) == QF_FAIL)
|
||||
{
|
||||
got_int = TRUE;
|
||||
break;
|
||||
}
|
||||
found_match = TRUE;
|
||||
if (--*tomatch == 0)
|
||||
break;
|
||||
if ((flags & VGR_GLOBAL) == 0)
|
||||
break;
|
||||
col = matches[pat_len - 1] + col + 1;
|
||||
if (col > (colnr_T)STRLEN(str))
|
||||
break;
|
||||
}
|
||||
found_match = TRUE;
|
||||
if (--*tomatch == 0)
|
||||
break;
|
||||
if ((flags & VGR_GLOBAL) == 0
|
||||
|| regmatch->endpos[0].lnum > 0)
|
||||
break;
|
||||
col = regmatch->endpos[0].col
|
||||
+ (col == regmatch->endpos[0].col);
|
||||
if (col > (colnr_T)STRLEN(ml_get_buf(buf, lnum, FALSE)))
|
||||
break;
|
||||
}
|
||||
line_breakcheck();
|
||||
if (got_int)
|
||||
@@ -6163,7 +6210,7 @@ vgr_process_files(
|
||||
// Try for a match in all lines of the buffer.
|
||||
// For ":1vimgrep" look for first match only.
|
||||
found_match = vgr_match_buflines(qf_get_curlist(qi),
|
||||
fname, buf, &cmd_args->regmatch,
|
||||
fname, buf, cmd_args->spat, &cmd_args->regmatch,
|
||||
&cmd_args->tomatch, duplicate_name, cmd_args->flags);
|
||||
|
||||
if (using_dummy)
|
||||
|
Reference in New Issue
Block a user