Mercurial > vim
comparison src/search.c @ 9647:847518911c0b v7.4.2100
commit https://github.com/vim/vim/commit/6835dc61aebca2b602d85a9d63c449ace58683b4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 24 17:33:05 2016 +0200
patch 7.4.2100
Problem: "cgn" and "dgn" do not work correctly with a single character
match and the replacement includes the searched pattern. (John
Beckett)
Solution: If the match is found in the wrong column try in the next column.
Turn the test into new style. (Christian Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 24 Jul 2016 17:45:05 +0200 |
parents | ab4fe611d205 |
children | bb00c661b3a4 |
comparison
equal
deleted
inserted
replaced
9646:c9c6aaff0184 | 9647:847518911c0b |
---|---|
4717 | 4717 |
4718 return OK; | 4718 return OK; |
4719 } | 4719 } |
4720 | 4720 |
4721 /* | 4721 /* |
4722 * Check if the pattern is one character or zero-width. | 4722 * Check if the pattern is one character long or zero-width. |
4723 * If move is TRUE, check from the beginning of the buffer, else from the | 4723 * If move is TRUE, check from the beginning of the buffer, else from the |
4724 * current cursor position. | 4724 * current cursor position. |
4725 * Returns TRUE, FALSE or -1 for failure. | 4725 * Returns TRUE, FALSE or -1 for failure. |
4726 */ | 4726 */ |
4727 static int | 4727 static int |
4732 int result = -1; | 4732 int result = -1; |
4733 pos_T pos; | 4733 pos_T pos; |
4734 int save_called_emsg = called_emsg; | 4734 int save_called_emsg = called_emsg; |
4735 int flag = 0; | 4735 int flag = 0; |
4736 | 4736 |
4737 if (pattern == NULL) | |
4738 pattern = spats[last_idx].pat; | |
4739 | |
4737 if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH, | 4740 if (search_regcomp(pattern, RE_SEARCH, RE_SEARCH, |
4738 SEARCH_KEEP, ®match) == FAIL) | 4741 SEARCH_KEEP, ®match) == FAIL) |
4739 return -1; | 4742 return -1; |
4740 | 4743 |
4744 /* init startcol correctly */ | |
4745 regmatch.startpos[0].col = -1; | |
4741 /* move to match */ | 4746 /* move to match */ |
4742 if (move) | 4747 if (move) |
4743 clearpos(&pos) | 4748 clearpos(&pos) |
4744 else | 4749 else |
4745 { | 4750 { |
4746 pos = curwin->w_cursor; | 4751 pos = curwin->w_cursor; |
4747 /* accept a match at the cursor position */ | 4752 /* accept a match at the cursor position */ |
4748 flag = SEARCH_START; | 4753 flag = SEARCH_START; |
4749 } | 4754 } |
4750 | 4755 |
4751 if (searchit(curwin, curbuf, &pos, FORWARD, spats[last_idx].pat, 1, | 4756 if (searchit(curwin, curbuf, &pos, FORWARD, pattern, 1, |
4752 SEARCH_KEEP + flag, RE_SEARCH, 0, NULL) != FAIL) | 4757 SEARCH_KEEP + flag, RE_SEARCH, 0, NULL) != FAIL) |
4753 { | 4758 { |
4754 /* Zero-width pattern should match somewhere, then we can check if | 4759 /* Zero-width pattern should match somewhere, then we can check if |
4755 * start and end are in the same position. */ | 4760 * start and end are in the same position. */ |
4756 called_emsg = FALSE; | 4761 called_emsg = FALSE; |
4757 nmatched = vim_regexec_multi(®match, curwin, curbuf, | 4762 do |
4758 pos.lnum, (colnr_T)0, NULL); | 4763 { |
4764 regmatch.startpos[0].col++; | |
4765 nmatched = vim_regexec_multi(®match, curwin, curbuf, | |
4766 pos.lnum, regmatch.startpos[0].col, NULL); | |
4767 if (!nmatched) | |
4768 break; | |
4769 } while (regmatch.startpos[0].col < pos.col); | |
4759 | 4770 |
4760 if (!called_emsg) | 4771 if (!called_emsg) |
4772 { | |
4761 result = (nmatched != 0 | 4773 result = (nmatched != 0 |
4762 && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum | 4774 && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum |
4763 && regmatch.startpos[0].col == regmatch.endpos[0].col); | 4775 && regmatch.startpos[0].col == regmatch.endpos[0].col); |
4764 | 4776 /* one char width */ |
4765 if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col) | 4777 if (!result && inc(&pos) >= 0 && pos.col == regmatch.endpos[0].col) |
4766 result = TRUE; | 4778 result = TRUE; |
4779 } | |
4767 } | 4780 } |
4768 | 4781 |
4769 called_emsg |= save_called_emsg; | 4782 called_emsg |= save_called_emsg; |
4770 vim_regfree(regmatch.regprog); | 4783 vim_regfree(regmatch.regprog); |
4771 return result; | 4784 return result; |