]>
Commit | Line | Data |
---|---|---|
0a7814d6 AG |
1 | To: vim-dev@vim.org |
2 | Subject: patch 7.1.067 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=ISO-8859-1 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.1.067 | |
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) | |
15 | Files: src/edit.c | |
16 | ||
17 | ||
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 | |
20 | *************** | |
21 | *** 2057,2063 **** | |
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. | |
26 | */ | |
27 | int | |
28 | ins_compl_add_infercase(str, len, icase, fname, dir, flags) | |
29 | --- 2057,2062 ---- | |
30 | *************** | |
31 | *** 2068,2121 **** | |
32 | int dir; | |
33 | int flags; | |
34 | { | |
35 | int has_lower = FALSE; | |
36 | int was_letter = FALSE; | |
37 | - int idx; | |
38 | ||
39 | ! if (p_ic && curbuf->b_p_inf && len < IOSIZE) | |
40 | { | |
41 | ! /* Infer case of completed part -- webb */ | |
42 | ! /* Use IObuff, str would change text in buffer! */ | |
43 | ! vim_strncpy(IObuff, str, len); | |
44 | ||
45 | ! /* Rule 1: Were any chars converted to lower? */ | |
46 | ! for (idx = 0; idx < compl_length; ++idx) | |
47 | { | |
48 | ! if (islower(compl_orig_text[idx])) | |
49 | { | |
50 | ! has_lower = TRUE; | |
51 | ! if (isupper(IObuff[idx])) | |
52 | ! { | |
53 | ! /* Rule 1 is satisfied */ | |
54 | ! for (idx = compl_length; idx < len; ++idx) | |
55 | ! IObuff[idx] = TOLOWER_LOC(IObuff[idx]); | |
56 | ! break; | |
57 | ! } | |
58 | } | |
59 | } | |
60 | ||
61 | ! /* | |
62 | ! * Rule 2: No lower case, 2nd consecutive letter converted to | |
63 | ! * upper case. | |
64 | ! */ | |
65 | ! if (!has_lower) | |
66 | { | |
67 | ! for (idx = 0; idx < compl_length; ++idx) | |
68 | { | |
69 | ! if (was_letter && isupper(compl_orig_text[idx]) | |
70 | ! && islower(IObuff[idx])) | |
71 | { | |
72 | ! /* Rule 2 is satisfied */ | |
73 | ! for (idx = compl_length; idx < len; ++idx) | |
74 | ! IObuff[idx] = TOUPPER_LOC(IObuff[idx]); | |
75 | ! break; | |
76 | } | |
77 | - was_letter = isalpha(compl_orig_text[idx]); | |
78 | } | |
79 | - } | |
80 | ||
81 | ! /* Copy the original case of the part we typed */ | |
82 | ! STRNCPY(IObuff, compl_orig_text, compl_length); | |
83 | ||
84 | return ins_compl_add(IObuff, len, icase, fname, NULL, dir, | |
85 | flags, FALSE); | |
86 | --- 2067,2213 ---- | |
87 | int dir; | |
88 | int flags; | |
89 | { | |
90 | + char_u *p; | |
91 | + int i, c; | |
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; | |
97 | ||
98 | ! if (p_ic && curbuf->b_p_inf) | |
99 | { | |
100 | ! /* Infer case of completed part. */ | |
101 | ||
102 | ! /* Find actual length of completion. */ | |
103 | ! #ifdef FEAT_MBYTE | |
104 | ! if (has_mbyte) | |
105 | { | |
106 | ! p = str; | |
107 | ! actual_len = 0; | |
108 | ! while (*p != NUL) | |
109 | { | |
110 | ! mb_ptr_adv(p); | |
111 | ! ++actual_len; | |
112 | } | |
113 | } | |
114 | + else | |
115 | + #endif | |
116 | + actual_len = len; | |
117 | ||
118 | ! /* Find actual length of original text. */ | |
119 | ! #ifdef FEAT_MBYTE | |
120 | ! if (has_mbyte) | |
121 | { | |
122 | ! p = compl_orig_text; | |
123 | ! actual_compl_length = 0; | |
124 | ! while (*p != NUL) | |
125 | { | |
126 | ! mb_ptr_adv(p); | |
127 | ! ++actual_compl_length; | |
128 | ! } | |
129 | ! } | |
130 | ! else | |
131 | ! #endif | |
132 | ! actual_compl_length = compl_length; | |
133 | ! | |
134 | ! /* Allocate wide character array for the completion and fill it. */ | |
135 | ! wca = (int *)alloc(actual_len * sizeof(int)); | |
136 | ! if (wca != NULL) | |
137 | ! { | |
138 | ! p = str; | |
139 | ! for (i = 0; i < actual_len; ++i) | |
140 | ! #ifdef FEAT_MBYTE | |
141 | ! if (has_mbyte) | |
142 | ! wca[i] = mb_ptr2char_adv(&p); | |
143 | ! else | |
144 | ! #endif | |
145 | ! wca[i] = *(p++); | |
146 | ! | |
147 | ! /* Rule 1: Were any chars converted to lower? */ | |
148 | ! p = compl_orig_text; | |
149 | ! for (i = 0; i < actual_compl_length; ++i) | |
150 | ! { | |
151 | ! #ifdef FEAT_MBYTE | |
152 | ! if (has_mbyte) | |
153 | ! c = mb_ptr2char_adv(&p); | |
154 | ! else | |
155 | ! #endif | |
156 | ! c = *(p++); | |
157 | ! if (MB_ISLOWER(c)) | |
158 | { | |
159 | ! has_lower = TRUE; | |
160 | ! if (MB_ISUPPER(wca[i])) | |
161 | ! { | |
162 | ! /* Rule 1 is satisfied. */ | |
163 | ! for (i = actual_compl_length; i < actual_len; ++i) | |
164 | ! wca[i] = MB_TOLOWER(wca[i]); | |
165 | ! break; | |
166 | ! } | |
167 | } | |
168 | } | |
169 | ||
170 | ! /* | |
171 | ! * Rule 2: No lower case, 2nd consecutive letter converted to | |
172 | ! * upper case. | |
173 | ! */ | |
174 | ! if (!has_lower) | |
175 | ! { | |
176 | ! p = compl_orig_text; | |
177 | ! for (i = 0; i < actual_compl_length; ++i) | |
178 | ! { | |
179 | ! #ifdef FEAT_MBYTE | |
180 | ! if (has_mbyte) | |
181 | ! c = mb_ptr2char_adv(&p); | |
182 | ! else | |
183 | ! #endif | |
184 | ! c = *(p++); | |
185 | ! if (was_letter && MB_ISUPPER(c) && MB_ISLOWER(wca[i])) | |
186 | ! { | |
187 | ! /* Rule 2 is satisfied. */ | |
188 | ! for (i = actual_compl_length; i < actual_len; ++i) | |
189 | ! wca[i] = MB_TOUPPER(wca[i]); | |
190 | ! break; | |
191 | ! } | |
192 | ! was_letter = MB_ISLOWER(c) || MB_ISUPPER(c); | |
193 | ! } | |
194 | ! } | |
195 | ! | |
196 | ! /* Copy the original case of the part we typed. */ | |
197 | ! p = compl_orig_text; | |
198 | ! for (i = 0; i < actual_compl_length; ++i) | |
199 | ! { | |
200 | ! #ifdef FEAT_MBYTE | |
201 | ! if (has_mbyte) | |
202 | ! c = mb_ptr2char_adv(&p); | |
203 | ! else | |
204 | ! #endif | |
205 | ! c = *(p++); | |
206 | ! if (MB_ISLOWER(c)) | |
207 | ! wca[i] = MB_TOLOWER(wca[i]); | |
208 | ! else if (MB_ISUPPER(c)) | |
209 | ! wca[i] = MB_TOUPPER(wca[i]); | |
210 | ! } | |
211 | ! | |
212 | ! /* | |
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. | |
217 | ! */ | |
218 | ! p = IObuff; | |
219 | ! i = 0; | |
220 | ! while (i < actual_len && (p - IObuff + 6) < IOSIZE) | |
221 | ! #ifdef FEAT_MBYTE | |
222 | ! if (has_mbyte) | |
223 | ! p += mb_char2bytes(wca[i++], p); | |
224 | ! else | |
225 | ! #endif | |
226 | ! *(p++) = wca[i++]; | |
227 | ! *p = NUL; | |
228 | ! | |
229 | ! vim_free(wca); | |
230 | ! } | |
231 | ||
232 | return ins_compl_add(IObuff, len, icase, fname, NULL, dir, | |
233 | flags, FALSE); | |
234 | *************** | |
235 | *** 2842,2847 **** | |
236 | --- 2934,2940 ---- | |
237 | /* | |
238 | * Add the other matches on the line | |
239 | */ | |
240 | + ptr = buf; | |
241 | while (!got_int) | |
242 | { | |
243 | /* Find start of the next word. Skip white | |
244 | *************** | |
245 | *** 2851,2857 **** | |
246 | break; | |
247 | wstart = ptr; | |
248 | ||
249 | ! /* Find end of the word and add it. */ | |
250 | #ifdef FEAT_MBYTE | |
251 | if (has_mbyte) | |
252 | /* Japanese words may have characters in | |
253 | --- 2944,2950 ---- | |
254 | break; | |
255 | wstart = ptr; | |
256 | ||
257 | ! /* Find end of the word. */ | |
258 | #ifdef FEAT_MBYTE | |
259 | if (has_mbyte) | |
260 | /* Japanese words may have characters in | |
261 | *************** | |
262 | *** 2868,2876 **** | |
263 | else | |
264 | #endif | |
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); | |
269 | } | |
270 | } | |
271 | if (add_r == OK) | |
272 | --- 2961,2972 ---- | |
273 | else | |
274 | #endif | |
275 | ptr = find_word_end(ptr); | |
276 | ! | |
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); | |
282 | } | |
283 | } | |
284 | if (add_r == OK) | |
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 | |
287 | *************** | |
288 | *** 668,669 **** | |
289 | --- 668,671 ---- | |
290 | { /* Add new patch number below this line */ | |
291 | + /**/ | |
292 | + 67, | |
293 | /**/ | |
294 | ||
295 | -- | |
296 | hundred-and-one symptoms of being an internet addict: | |
297 | 128. You can access the Net -- via your portable and cellular phone. | |
298 | ||
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 /// |