Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updated for version 7.3.636

Problem:    Not all zero-width matches handled correctly for "gn".
Solution:   Move zero-width detection to a separate function. (Christian
	    Brabandt)
  • Loading branch information...
commit 7a2b881cc0c55b6dff6fefb4ecd78e4442629b26 1 parent 3d75bd4
Bram Moolenaar authored

Showing 2 changed files with 44 additions and 19 deletions. Show diff stats Hide diff stats

  1. +42 19 src/search.c
  2. +2 0  src/version.c
61 src/search.c
@@ -4526,6 +4526,8 @@ current_quote(oap, count, include, quotechar)
4526 4526 #endif /* FEAT_TEXTOBJ */
4527 4527
4528 4528 #if defined(FEAT_VISUAL) || defined(PROTO)
  4529 +static int is_zerowidth __ARGS((char_u *pattern));
  4530 +
4529 4531 /*
4530 4532 * Find next search match under cursor, cursor at end.
4531 4533 * Used while an operator is pending, and in Visual mode.
@@ -4546,11 +4548,8 @@ current_search(count, forward)
4546 4548 int visual_active = FALSE;
4547 4549 int flags = 0;
4548 4550 pos_T save_VIsual;
4549   - regmmatch_T regmatch;
4550   - int nmatched = 0;
4551 4551 int zerowidth = FALSE;
4552 4552
4553   -
4554 4553 /* wrapping should not occur */
4555 4554 p_ws = FALSE;
4556 4555
@@ -4583,23 +4582,10 @@ current_search(count, forward)
4583 4582 else
4584 4583 orig_pos = pos = start_pos = curwin->w_cursor;
4585 4584
4586   - /*
4587   - * Check for zero-width pattern.
4588   - */
4589   - if (search_regcomp(spats[last_idx].pat, RE_SEARCH, RE_SEARCH,
4590   - ((SEARCH_HIS + SEARCH_KEEP)), &regmatch) == FAIL)
4591   - return FAIL;
4592   -
4593   - /* Zero-width pattern should match somewhere, then we can check if start
4594   - * and end are in the same position. */
4595   - nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
4596   - curwin->w_cursor.lnum, (colnr_T)0, NULL);
4597   - if (called_emsg)
  4585 + /* Is the pattern is zero-width? */
  4586 + zerowidth = is_zerowidth(spats[last_idx].pat);
  4587 + if (zerowidth == -1)
4598 4588 return FAIL;
4599   - if (nmatched && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
4600   - && regmatch.endpos[0].col == regmatch.startpos[0].col)
4601   - zerowidth = TRUE;
4602   - vim_free(regmatch.regprog);
4603 4589
4604 4590 /*
4605 4591 * The trick is to first search backwards and then search forward again,
@@ -4693,6 +4679,43 @@ current_search(count, forward)
4693 4679
4694 4680 return OK;
4695 4681 }
  4682 +
  4683 +/*
  4684 + * Check if the pattern is zero-width.
  4685 + * Returns TRUE, FALSE or -1 for failure.
  4686 + */
  4687 + static int
  4688 +is_zerowidth(pattern)
  4689 + char_u *pattern;
  4690 +{
  4691 + regmmatch_T regmatch;
  4692 + int nmatched = 0;
  4693 + int result = -1;
  4694 + pos_T pos;
  4695 +
  4696 + if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH,
  4697 + SEARCH_KEEP, &regmatch) == FAIL)
  4698 + return -1;
  4699 +
  4700 + /* move to match */
  4701 + clearpos(&pos);
  4702 + if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1,
  4703 + SEARCH_KEEP, RE_SEARCH, 0, NULL) != FAIL)
  4704 + {
  4705 + /* Zero-width pattern should match somewhere, then we can check if
  4706 + * start and end are in the same position. */
  4707 + nmatched = vim_regexec_multi(&regmatch, curwin, curbuf,
  4708 + pos.lnum, (colnr_T)0, NULL);
  4709 +
  4710 + if (!called_emsg)
  4711 + result = (nmatched != 0
  4712 + && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum
  4713 + && regmatch.startpos[0].col == regmatch.endpos[0].col);
  4714 + }
  4715 +
  4716 + vim_free(regmatch.regprog);
  4717 + return result;
  4718 +}
4696 4719 #endif /* FEAT_VISUAL */
4697 4720
4698 4721 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(FEAT_TEXTOBJ) \
2  src/version.c
@@ -720,6 +720,8 @@ static char *(features[]) =
720 720 static int included_patches[] =
721 721 { /* Add new patch number below this line */
722 722 /**/
  723 + 636,
  724 +/**/
723 725 635,
724 726 /**/
725 727 634,

0 comments on commit 7a2b881

Please sign in to comment.
Something went wrong with that request. Please try again.