Skip to content

Instantly share code, notes, and snippets.

@rbtnn
Created December 26, 2019 14:42
Show Gist options
  • Save rbtnn/530d1be63c108f45b3854ed6831d4ea8 to your computer and use it in GitHub Desktop.
Save rbtnn/530d1be63c108f45b3854ed6831d4ea8 to your computer and use it in GitHub Desktop.
:vimgrepに単純な文字列検索オプションを付けた修正の差分
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 491049194..f47750561 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -6421,9 +6421,9 @@ ex_drop(exarg_T *eap)
}
/*
- * Skip over the pattern argument of ":vimgrep /pat/[g][j]".
+ * Skip over the pattern argument of ":vimgrep /pat/[g][j][p]".
* Put the start of the pattern in "*s", unless "s" is NULL.
- * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP.
+ * If "flags" is not NULL put the flags in it: VGR_GLOBAL, VGR_NOJUMP, VGR_PLAINTEXT.
* If "s" is not NULL terminate the pattern with a NUL.
* Return a pointer to the char just past the pattern plus flags.
*/
@@ -6443,7 +6443,7 @@ skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
}
else
{
- // ":vimgrep /pattern/[g][j] fname"
+ // ":vimgrep /pattern/[g][j][p] fname"
if (s != NULL)
*s = p + 1;
c = *p;
@@ -6457,11 +6457,13 @@ skip_vimgrep_pat(char_u *p, char_u **s, int *flags)
++p;
// Find the flags
- while (*p == 'g' || *p == 'j')
+ while (*p == 'g' || *p == 'j' || *p == 'p')
{
if (flags != NULL)
{
- if (*p == 'g')
+ if (*p == 'p')
+ *flags |= VGR_PLAINTEXT;
+ else if (*p == 'g')
*flags |= VGR_GLOBAL;
else
*flags |= VGR_NOJUMP;
diff --git a/src/quickfix.c b/src/quickfix.c
index 2e07403a8..df1f6b30d 100644
--- a/src/quickfix.c
+++ b/src/quickfix.c
@@ -5735,8 +5735,25 @@ vgr_match_buflines(
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)
+ long n = 0;
+ if (flags & VGR_PLAINTEXT)
+ {
+ char_u *p1 = ml_get_buf(buf, lnum, FALSE);
+ char_u *p2 = vim_strsave(((nfa_regprog_T *)regmatch->regprog)->pattern);
+ char_u *pos = (char *)strstr(p1, p2);
+ regmatch->startpos[0].lnum = 0;
+ regmatch->endpos[0].lnum = 0;
+ if (pos != NULL)
+ {
+ n = 1;
+ col = pos - p1;
+ regmatch->startpos[0].col = col;
+ regmatch->endpos[0].col = col;
+ }
+ }
+ else
+ n = vim_regexec_multi(regmatch, curwin, buf, lnum, col, NULL, NULL);
+ while (n > 0)
{
// Pass the buffer number so that it gets used even for a
// dummy buffer, unless duplicate_name is set, then the
diff --git a/src/vim.h b/src/vim.h
index a01d4b290..c068dd603 100644
--- a/src/vim.h
+++ b/src/vim.h
@@ -2440,6 +2440,7 @@ typedef enum {
// flags for skip_vimgrep_pat()
#define VGR_GLOBAL 1
#define VGR_NOJUMP 2
+#define VGR_PLAINTEXT 4
// behavior for bad character, "++bad=" argument
#define BAD_REPLACE '?' // replace it with '?' (default)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment