]>
Commit | Line | Data |
---|---|---|
5a088057 KK |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.625 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.3.625 | |
11 | Problem: "gn" does not handle zero-width matches correctly. | |
12 | Solution: Handle zero-width patterns specially. (Christian Brabandt) | |
13 | Files: src/search.c | |
14 | ||
15 | ||
16 | *** ../vim-7.3.624/src/search.c 2012-08-02 21:24:38.000000000 +0200 | |
17 | --- src/search.c 2012-08-08 15:25:12.000000000 +0200 | |
18 | *************** | |
19 | *** 4546,4551 **** | |
20 | --- 4546,4554 ---- | |
21 | int visual_active = FALSE; | |
22 | int flags = 0; | |
23 | pos_T save_VIsual; | |
24 | + regmmatch_T regmatch; | |
25 | + int nmatched = 0; | |
26 | + int zerowidth = FALSE; | |
27 | ||
28 | ||
29 | /* wrapping should not occur */ | |
30 | *************** | |
31 | *** 4581,4603 **** | |
32 | orig_pos = pos = start_pos = curwin->w_cursor; | |
33 | ||
34 | /* | |
35 | * The trick is to first search backwards and then search forward again, | |
36 | * so that a match at the current cursor position will be correctly | |
37 | * captured. | |
38 | */ | |
39 | for (i = 0; i < 2; i++) | |
40 | { | |
41 | - if (i && count == 1) | |
42 | - flags = SEARCH_START; | |
43 | - | |
44 | if (forward) | |
45 | dir = i; | |
46 | else | |
47 | dir = !i; | |
48 | result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD), | |
49 | spats[last_idx].pat, (long) (i ? count : 1), | |
50 | ! SEARCH_KEEP | flags | (dir ? 0 : SEARCH_END), | |
51 | ! RE_SEARCH, 0, NULL); | |
52 | ||
53 | /* First search may fail, but then start searching from the | |
54 | * beginning of the file (cursor might be on the search match) | |
55 | --- 4584,4625 ---- | |
56 | orig_pos = pos = start_pos = curwin->w_cursor; | |
57 | ||
58 | /* | |
59 | + * Check for zero-width pattern. | |
60 | + */ | |
61 | + if (search_regcomp(spats[last_idx].pat, RE_SEARCH, RE_SEARCH, | |
62 | + ((SEARCH_HIS + SEARCH_KEEP)), ®match) == FAIL) | |
63 | + return FAIL; | |
64 | + | |
65 | + /* Zero-width pattern should match somewhere, then we can check if start | |
66 | + * and end are in the same position. */ | |
67 | + nmatched = vim_regexec_multi(®match, curwin, curbuf, | |
68 | + curwin->w_cursor.lnum, (colnr_T)0, NULL); | |
69 | + if (called_emsg) | |
70 | + return FAIL; | |
71 | + if (nmatched && regmatch.startpos[0].lnum == regmatch.endpos[0].lnum | |
72 | + && regmatch.endpos[0].col == regmatch.startpos[0].col) | |
73 | + zerowidth = TRUE; | |
74 | + vim_free(regmatch.regprog); | |
75 | + | |
76 | + /* | |
77 | * The trick is to first search backwards and then search forward again, | |
78 | * so that a match at the current cursor position will be correctly | |
79 | * captured. | |
80 | */ | |
81 | for (i = 0; i < 2; i++) | |
82 | { | |
83 | if (forward) | |
84 | dir = i; | |
85 | else | |
86 | dir = !i; | |
87 | + | |
88 | + flags = 0; | |
89 | + if (!dir && !zerowidth) | |
90 | + flags = SEARCH_END; | |
91 | + | |
92 | result = searchit(curwin, curbuf, &pos, (dir ? FORWARD : BACKWARD), | |
93 | spats[last_idx].pat, (long) (i ? count : 1), | |
94 | ! SEARCH_KEEP | flags, RE_SEARCH, 0, NULL); | |
95 | ||
96 | /* First search may fail, but then start searching from the | |
97 | * beginning of the file (cursor might be on the search match) | |
98 | *************** | |
99 | *** 4629,4638 **** | |
100 | } | |
101 | ||
102 | start_pos = pos; | |
103 | ! flags = (forward ? SEARCH_END : 0); | |
104 | ||
105 | ! /* move to match */ | |
106 | ! result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD), | |
107 | spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL); | |
108 | ||
109 | if (!VIsual_active) | |
110 | --- 4651,4662 ---- | |
111 | } | |
112 | ||
113 | start_pos = pos; | |
114 | ! flags = forward ? SEARCH_END : 0; | |
115 | ||
116 | ! /* move to match, except for zero-width matches, in which case, we are | |
117 | ! * already on the next match */ | |
118 | ! if (!zerowidth) | |
119 | ! result = searchit(curwin, curbuf, &pos, (forward ? FORWARD : BACKWARD), | |
120 | spats[last_idx].pat, 0L, flags | SEARCH_KEEP, RE_SEARCH, 0, NULL); | |
121 | ||
122 | if (!VIsual_active) | |
123 | *** ../vim-7.3.624/src/version.c 2012-08-08 14:33:16.000000000 +0200 | |
124 | --- src/version.c 2012-08-08 15:21:53.000000000 +0200 | |
125 | *************** | |
126 | *** 716,717 **** | |
127 | --- 716,719 ---- | |
128 | { /* Add new patch number below this line */ | |
129 | + /**/ | |
130 | + 625, | |
131 | /**/ | |
132 | ||
133 | -- | |
134 | hundred-and-one symptoms of being an internet addict: | |
135 | 222. You send more than 20 personal e-mails a day. | |
136 | ||
137 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
138 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
139 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
140 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |