4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=ISO-8859-1
7 Content-Transfer-Encoding: 8bit
11 Problem: 'thesaurus' doesn't work when 'infercase' is set. (Mohsin)
12 Solution: Don't copy the characters being completed but check the case and
13 apply it to the suggested word. Also fix that the first word in
14 the thesaurus line is not used. (Martin Toft)
18 *** ../vim-7.1.066/src/edit.c Sun Jul 29 15:02:34 2007
19 --- src/edit.c Sat Aug 11 17:16:51 2007
22 * case of the originally typed text is used, and the case of the completed
23 * text is inferred, ie this tries to work out what case you probably wanted
24 * the rest of the word to be in -- webb
25 - * TODO: make this work for multi-byte characters.
28 ins_compl_add_infercase(str, len, icase, fname, dir, flags)
35 int has_lower = FALSE;
36 int was_letter = FALSE;
39 ! if (p_ic && curbuf->b_p_inf && len < IOSIZE)
41 ! /* Infer case of completed part -- webb */
42 ! /* Use IObuff, str would change text in buffer! */
43 ! vim_strncpy(IObuff, str, len);
45 ! /* Rule 1: Were any chars converted to lower? */
46 ! for (idx = 0; idx < compl_length; ++idx)
48 ! if (islower(compl_orig_text[idx]))
51 ! if (isupper(IObuff[idx]))
53 ! /* Rule 1 is satisfied */
54 ! for (idx = compl_length; idx < len; ++idx)
55 ! IObuff[idx] = TOLOWER_LOC(IObuff[idx]);
62 ! * Rule 2: No lower case, 2nd consecutive letter converted to
67 ! for (idx = 0; idx < compl_length; ++idx)
69 ! if (was_letter && isupper(compl_orig_text[idx])
70 ! && islower(IObuff[idx]))
72 ! /* Rule 2 is satisfied */
73 ! for (idx = compl_length; idx < len; ++idx)
74 ! IObuff[idx] = TOUPPER_LOC(IObuff[idx]);
77 - was_letter = isalpha(compl_orig_text[idx]);
81 ! /* Copy the original case of the part we typed */
82 ! STRNCPY(IObuff, compl_orig_text, compl_length);
84 return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
92 + int actual_len; /* Take multi-byte characters */
93 + int actual_compl_length; /* into account. */
94 + int *wca; /* Wide character array. */
95 int has_lower = FALSE;
96 int was_letter = FALSE;
98 ! if (p_ic && curbuf->b_p_inf)
100 ! /* Infer case of completed part. */
102 ! /* Find actual length of completion. */
118 ! /* Find actual length of original text. */
122 ! p = compl_orig_text;
123 ! actual_compl_length = 0;
127 ! ++actual_compl_length;
132 ! actual_compl_length = compl_length;
134 ! /* Allocate wide character array for the completion and fill it. */
135 ! wca = (int *)alloc(actual_len * sizeof(int));
139 ! for (i = 0; i < actual_len; ++i)
142 ! wca[i] = mb_ptr2char_adv(&p);
147 ! /* Rule 1: Were any chars converted to lower? */
148 ! p = compl_orig_text;
149 ! for (i = 0; i < actual_compl_length; ++i)
153 ! c = mb_ptr2char_adv(&p);
160 ! if (MB_ISUPPER(wca[i]))
162 ! /* Rule 1 is satisfied. */
163 ! for (i = actual_compl_length; i < actual_len; ++i)
164 ! wca[i] = MB_TOLOWER(wca[i]);
171 ! * Rule 2: No lower case, 2nd consecutive letter converted to
176 ! p = compl_orig_text;
177 ! for (i = 0; i < actual_compl_length; ++i)
181 ! c = mb_ptr2char_adv(&p);
185 ! if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i]))
187 ! /* Rule 2 is satisfied. */
188 ! for (i = actual_compl_length; i < actual_len; ++i)
189 ! wca[i] = MB_TOUPPER(wca[i]);
192 ! was_letter = MB_ISLOWER(c) || MB_ISUPPER(c);
196 ! /* Copy the original case of the part we typed. */
197 ! p = compl_orig_text;
198 ! for (i = 0; i < actual_compl_length; ++i)
202 ! c = mb_ptr2char_adv(&p);
207 ! wca[i] = MB_TOLOWER(wca[i]);
208 ! else if (MB_ISUPPER(c))
209 ! wca[i] = MB_TOUPPER(wca[i]);
213 ! * Generate encoding specific output from wide character array.
214 ! * Multi-byte characters can occupy up to five bytes more than
215 ! * ASCII characters, and we also need one byte for NUL, so stay
216 ! * six bytes away from the edge of IObuff.
220 ! while (i < actual_len && (p - IObuff + 6) < IOSIZE)
223 ! p += mb_char2bytes(wca[i++], p);
232 return ins_compl_add(IObuff, len, icase, fname, NULL, dir,
238 * Add the other matches on the line
243 /* Find start of the next word. Skip white
249 ! /* Find end of the word and add it. */
252 /* Japanese words may have characters in
257 ! /* Find end of the word. */
260 /* Japanese words may have characters in
265 ptr = find_word_end(ptr);
266 ! add_r = ins_compl_add_infercase(wstart,
267 ! (int)(ptr - wstart),
268 ! p_ic, files[i], *dir, 0);
275 ptr = find_word_end(ptr);
277 ! /* Add the word. Skip the regexp match. */
278 ! if (wstart != regmatch->startp[0])
279 ! add_r = ins_compl_add_infercase(wstart,
280 ! (int)(ptr - wstart),
281 ! p_ic, files[i], *dir, 0);
285 *** ../vim-7.1.066/src/version.c Sun Aug 12 15:50:26 2007
286 --- src/version.c Sun Aug 12 16:36:34 2007
290 { /* Add new patch number below this line */
296 hundred-and-one symptoms of being an internet addict:
297 128. You can access the Net -- via your portable and cellular phone.
299 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
300 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
301 \\\ download, build and distribute -- http://www.A-A-P.org ///
302 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///