1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: When both a middle part of 'comments' matches and an end part, the
12 middle part was used errornously.
13 Solution: After finding the middle part match continue looking for a better
14 end part match. (partly by Lech Lorens)
15 Files: src/misc1.c, src/testdir/test3.in, src/testdir/test3.ok
18 *** ../vim-7.3.179/src/misc1.c 2011-05-10 11:56:26.000000000 +0200
19 --- src/misc1.c 2011-05-10 13:24:38.000000000 +0200
23 char_u part_buf[COM_MAX_LEN]; /* buffer for one option part */
24 char_u *string; /* pointer to comment string */
26 + int middle_match_len = 0;
28 + char_u *saved_flags;
31 while (vim_iswhite(line[i])) /* leading white space is ignored */
35 * Repeat to match several nested comment strings.
40 * scan through the 'comments' option for a match
43 * Repeat to match several nested comment strings.
45 ! while (line[i] != NUL)
48 * scan through the 'comments' option for a match
52 for (list = curbuf->b_p_com; *list; )
55 ! * Get one option part into part_buf[]. Advance list to next one.
56 ! * put string at start of string.
58 ! if (!got_com && flags != NULL) /* remember where flags started */
60 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
61 string = vim_strchr(part_buf, ':');
62 if (string == NULL) /* missing ':', ignore this part */
64 *string++ = NUL; /* isolate flags from string */
67 ! * When already found a nested comment, only accept further
70 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
73 ! /* When 'O' flag used don't use for "O" command */
74 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
78 ! * Line contents and string must match.
79 * When string starts with white space, must have some white space
80 * (but the amount does not need to match, there might be a mix of
83 if (vim_iswhite(string[0]))
85 if (i == 0 || !vim_iswhite(line[i - 1]))
87 while (vim_iswhite(string[0]))
90 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
96 ! * When 'b' flag used, there must be white space or an
97 ! * end-of-line after the string in the line.
99 if (vim_strchr(part_buf, COM_BLANK) != NULL
100 && !vim_iswhite(line[i + j]) && line[i + j] != NUL)
104 ! * We have found a match, stop searching.
113 ! * No match found, stop scanning.
119 ! * Include any trailing white space.
121 while (vim_iswhite(line[i]))
125 ! * If this comment doesn't nest, stop here.
127 if (vim_strchr(part_buf, COM_NEST) == NULL)
130 return (got_com ? i : 0);
135 for (list = curbuf->b_p_com; *list; )
137 ! /* Get one option part into part_buf[]. Advance "list" to next
138 ! * one. Put "string" at start of string. */
139 ! if (!got_com && flags != NULL)
140 ! *flags = list; /* remember where flags started */
142 (void)copy_option_part(&list, part_buf, COM_MAX_LEN, ",");
143 string = vim_strchr(part_buf, ':');
144 if (string == NULL) /* missing ':', ignore this part */
146 *string++ = NUL; /* isolate flags from string */
148 ! /* If we found a middle match previously, use that match when this
149 ! * is not a middle or end. */
150 ! if (middle_match_len != 0
151 ! && vim_strchr(part_buf, COM_MIDDLE) == NULL
152 ! && vim_strchr(part_buf, COM_END) == NULL)
155 ! /* When we already found a nested comment, only accept further
156 ! * nested comments. */
157 if (got_com && vim_strchr(part_buf, COM_NEST) == NULL)
160 ! /* When 'O' flag present and using "O" command skip this one. */
161 if (backward && vim_strchr(part_buf, COM_NOBACK) != NULL)
164 ! /* Line contents and string must match.
165 * When string starts with white space, must have some white space
166 * (but the amount does not need to match, there might be a mix of
167 ! * TABs and spaces). */
168 if (vim_iswhite(string[0]))
170 if (i == 0 || !vim_iswhite(line[i - 1]))
171 ! continue; /* missing shite space */
172 while (vim_iswhite(string[0]))
175 for (j = 0; string[j] != NUL && string[j] == line[i + j]; ++j)
177 if (string[j] != NUL)
178 ! continue; /* string doesn't match */
180 ! /* When 'b' flag used, there must be white space or an
181 ! * end-of-line after the string in the line. */
182 if (vim_strchr(part_buf, COM_BLANK) != NULL
183 && !vim_iswhite(line[i + j]) && line[i + j] != NUL)
186 ! /* We have found a match, stop searching unless this is a middle
187 ! * comment. The middle comment can be a substring of the end
188 ! * comment in which case it's better to return the length of the
189 ! * end comment and its flags. Thus we keep searching with middle
190 ! * and end matches and use an end match if it matches better. */
191 ! if (vim_strchr(part_buf, COM_MIDDLE) != NULL)
193 ! if (middle_match_len == 0)
195 ! middle_match_len = j;
196 ! saved_flags = prev_list;
200 ! if (middle_match_len != 0 && j > middle_match_len)
201 ! /* Use this match instead of the middle match, since it's a
202 ! * longer thus better match. */
203 ! middle_match_len = 0;
205 ! if (middle_match_len == 0)
211 ! if (middle_match_len != 0)
213 ! /* Use the previously found middle match after failing to find a
214 ! * match with an end. */
215 ! if (!got_com && flags != NULL)
216 ! *flags = saved_flags;
217 ! i += middle_match_len;
221 ! /* No match found, stop scanning. */
225 ! /* Include any trailing white space. */
226 while (vim_iswhite(line[i]))
229 ! /* If this comment doesn't nest, stop here. */
231 if (vim_strchr(part_buf, COM_NEST) == NULL)
235 return (got_com ? i : 0);
238 *** ../vim-7.3.179/src/testdir/test3.in 2011-05-10 11:56:26.000000000 +0200
239 --- src/testdir/test3.in 2011-05-10 12:05:50.000000000 +0200
246 + :set com=s1:/*,m:*,ex:*/
253 + * This is a comment.
258 :g/^STARTTEST/.,/^ENDTEST/d
259 :1;/start of AUTO/,$wq! test.out
261 *** ../vim-7.3.179/src/testdir/test3.ok 2011-05-10 11:56:26.000000000 +0200
262 --- src/testdir/test3.ok 2011-05-10 12:05:50.000000000 +0200
273 + * This is a comment.
278 *** ../vim-7.3.179/src/version.c 2011-05-10 11:56:26.000000000 +0200
279 --- src/version.c 2011-05-10 13:37:28.000000000 +0200
283 { /* Add new patch number below this line */
289 "Thou shalt not follow the Null Pointer, for at its end Chaos and
292 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
293 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
294 \\\ an exciting new programming language -- http://www.Zimbu.org ///
295 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///