]>
Commit | Line | Data |
---|---|---|
437d9c61 ER |
1 | To: vim_dev@googlegroups.com |
2 | Subject: Patch 7.3.198 | |
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.198 | |
11 | Problem: No completion for ":lang". | |
12 | Solution: Get locales to complete from. (Dominique Pelle) | |
13 | Files: src/eval.c, src/ex_cmds2.c, src/ex_getln.c, | |
14 | src/proto/ex_cmds2.pro, src/proto/ex_getln.pro, src/vim.h | |
15 | ||
16 | ||
17 | *** ../mercurial/vim73/src/eval.c 2011-05-19 17:25:36.000000000 +0200 | |
18 | --- src/eval.c 2011-05-19 17:52:02.000000000 +0200 | |
19 | *************** | |
20 | *** 911,916 **** | |
21 | --- 911,917 ---- | |
22 | hash_clear(&compat_hashtab); | |
23 | ||
24 | free_scriptnames(); | |
25 | + free_locales(); | |
26 | ||
27 | /* global variables */ | |
28 | vars_clear(&globvarht); | |
29 | *** ../mercurial/vim73/src/ex_cmds2.c 2011-05-10 16:41:13.000000000 +0200 | |
30 | --- src/ex_cmds2.c 2011-05-19 18:16:54.000000000 +0200 | |
31 | *************** | |
32 | *** 1476,1482 **** | |
33 | #endif | |
34 | ||
35 | /* | |
36 | ! * Ask the user what to do when abondoning a changed buffer. | |
37 | * Must check 'write' option first! | |
38 | */ | |
39 | void | |
40 | --- 1476,1482 ---- | |
41 | #endif | |
42 | ||
43 | /* | |
44 | ! * Ask the user what to do when abandoning a changed buffer. | |
45 | * Must check 'write' option first! | |
46 | */ | |
47 | void | |
48 | *************** | |
49 | *** 4153,4158 **** | |
50 | --- 4153,4234 ---- | |
51 | } | |
52 | ||
53 | # if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
54 | + | |
55 | + static char_u **locales = NULL; /* Array of all available locales */ | |
56 | + static int did_init_locales = FALSE; | |
57 | + | |
58 | + static void init_locales __ARGS((void)); | |
59 | + static char_u **find_locales __ARGS((void)); | |
60 | + | |
61 | + /* | |
62 | + * Lazy initialization of all available locales. | |
63 | + */ | |
64 | + static void | |
65 | + init_locales() | |
66 | + { | |
67 | + if (!did_init_locales) | |
68 | + { | |
69 | + did_init_locales = TRUE; | |
70 | + locales = find_locales(); | |
71 | + } | |
72 | + } | |
73 | + | |
74 | + /* Return an array of strings for all available locales + NULL for the | |
75 | + * last element. Return NULL in case of error. */ | |
76 | + static char_u ** | |
77 | + find_locales() | |
78 | + { | |
79 | + garray_T locales_ga; | |
80 | + char_u *loc; | |
81 | + | |
82 | + /* Find all available locales by running command "locale -a". If this | |
83 | + * doesn't work we won't have completion. */ | |
84 | + char_u *locale_a = get_cmd_output((char_u *)"locale -a", | |
85 | + NULL, SHELL_SILENT); | |
86 | + if (locale_a == NULL) | |
87 | + return NULL; | |
88 | + ga_init2(&locales_ga, sizeof(char_u *), 20); | |
89 | + | |
90 | + /* Transform locale_a string where each locale is separated by "\n" | |
91 | + * into an array of locale strings. */ | |
92 | + loc = (char_u *)strtok((char *)locale_a, "\n"); | |
93 | + | |
94 | + while (loc != NULL) | |
95 | + { | |
96 | + if (ga_grow(&locales_ga, 1) == FAIL) | |
97 | + break; | |
98 | + loc = vim_strsave(loc); | |
99 | + if (loc == NULL) | |
100 | + break; | |
101 | + | |
102 | + ((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc; | |
103 | + loc = (char_u *)strtok(NULL, "\n"); | |
104 | + } | |
105 | + vim_free(locale_a); | |
106 | + if (ga_grow(&locales_ga, 1) == FAIL) | |
107 | + { | |
108 | + ga_clear(&locales_ga); | |
109 | + return NULL; | |
110 | + } | |
111 | + ((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL; | |
112 | + return (char_u **)locales_ga.ga_data; | |
113 | + } | |
114 | + | |
115 | + # if defined(EXITFREE) || defined(PROTO) | |
116 | + void | |
117 | + free_locales() | |
118 | + { | |
119 | + int i; | |
120 | + if (locales != NULL) | |
121 | + { | |
122 | + for (i = 0; locales[i] != NULL; i++) | |
123 | + vim_free(locales[i]); | |
124 | + vim_free(locales); | |
125 | + locales = NULL; | |
126 | + } | |
127 | + } | |
128 | + # endif | |
129 | + | |
130 | /* | |
131 | * Function given to ExpandGeneric() to obtain the possible arguments of the | |
132 | * ":language" command. | |
133 | *************** | |
134 | *** 4168,4174 **** | |
135 | return (char_u *)"ctype"; | |
136 | if (idx == 2) | |
137 | return (char_u *)"time"; | |
138 | ! return NULL; | |
139 | } | |
140 | # endif | |
141 | ||
142 | --- 4244,4268 ---- | |
143 | return (char_u *)"ctype"; | |
144 | if (idx == 2) | |
145 | return (char_u *)"time"; | |
146 | ! | |
147 | ! init_locales(); | |
148 | ! if (locales == NULL) | |
149 | ! return NULL; | |
150 | ! return locales[idx - 3]; | |
151 | ! } | |
152 | ! | |
153 | ! /* | |
154 | ! * Function given to ExpandGeneric() to obtain the available locales. | |
155 | ! */ | |
156 | ! char_u * | |
157 | ! get_locales(xp, idx) | |
158 | ! expand_T *xp UNUSED; | |
159 | ! int idx; | |
160 | ! { | |
161 | ! init_locales(); | |
162 | ! if (locales == NULL) | |
163 | ! return NULL; | |
164 | ! return locales[idx]; | |
165 | } | |
166 | # endif | |
167 | ||
168 | *** ../mercurial/vim73/src/ex_getln.c 2011-05-19 14:50:49.000000000 +0200 | |
169 | --- src/ex_getln.c 2011-05-19 18:18:49.000000000 +0200 | |
170 | *************** | |
171 | *** 4571,4618 **** | |
172 | int context; | |
173 | char_u *((*func)__ARGS((expand_T *, int))); | |
174 | int ic; | |
175 | } tab[] = | |
176 | { | |
177 | ! {EXPAND_COMMANDS, get_command_name, FALSE}, | |
178 | ! {EXPAND_BEHAVE, get_behave_arg, TRUE}, | |
179 | #ifdef FEAT_USR_CMDS | |
180 | ! {EXPAND_USER_COMMANDS, get_user_commands, FALSE}, | |
181 | ! {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE}, | |
182 | ! {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE}, | |
183 | ! {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE}, | |
184 | #endif | |
185 | #ifdef FEAT_EVAL | |
186 | ! {EXPAND_USER_VARS, get_user_var_name, FALSE}, | |
187 | ! {EXPAND_FUNCTIONS, get_function_name, FALSE}, | |
188 | ! {EXPAND_USER_FUNC, get_user_func_name, FALSE}, | |
189 | ! {EXPAND_EXPRESSION, get_expr_name, FALSE}, | |
190 | #endif | |
191 | #ifdef FEAT_MENU | |
192 | ! {EXPAND_MENUS, get_menu_name, FALSE}, | |
193 | ! {EXPAND_MENUNAMES, get_menu_names, FALSE}, | |
194 | #endif | |
195 | #ifdef FEAT_SYN_HL | |
196 | ! {EXPAND_SYNTAX, get_syntax_name, TRUE}, | |
197 | #endif | |
198 | ! {EXPAND_HIGHLIGHT, get_highlight_name, TRUE}, | |
199 | #ifdef FEAT_AUTOCMD | |
200 | ! {EXPAND_EVENTS, get_event_name, TRUE}, | |
201 | ! {EXPAND_AUGROUP, get_augroup_name, TRUE}, | |
202 | #endif | |
203 | #ifdef FEAT_CSCOPE | |
204 | ! {EXPAND_CSCOPE, get_cscope_name, TRUE}, | |
205 | #endif | |
206 | #ifdef FEAT_SIGNS | |
207 | ! {EXPAND_SIGN, get_sign_name, TRUE}, | |
208 | #endif | |
209 | #ifdef FEAT_PROFILE | |
210 | ! {EXPAND_PROFILE, get_profile_name, TRUE}, | |
211 | #endif | |
212 | #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
213 | && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
214 | ! {EXPAND_LANGUAGE, get_lang_arg, TRUE}, | |
215 | #endif | |
216 | ! {EXPAND_ENV_VARS, get_env_name, TRUE}, | |
217 | }; | |
218 | int i; | |
219 | ||
220 | --- 4571,4620 ---- | |
221 | int context; | |
222 | char_u *((*func)__ARGS((expand_T *, int))); | |
223 | int ic; | |
224 | + int escaped; | |
225 | } tab[] = | |
226 | { | |
227 | ! {EXPAND_COMMANDS, get_command_name, FALSE, TRUE}, | |
228 | ! {EXPAND_BEHAVE, get_behave_arg, TRUE, TRUE}, | |
229 | #ifdef FEAT_USR_CMDS | |
230 | ! {EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE}, | |
231 | ! {EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE}, | |
232 | ! {EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE}, | |
233 | ! {EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE}, | |
234 | #endif | |
235 | #ifdef FEAT_EVAL | |
236 | ! {EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE}, | |
237 | ! {EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE}, | |
238 | ! {EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE}, | |
239 | ! {EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE}, | |
240 | #endif | |
241 | #ifdef FEAT_MENU | |
242 | ! {EXPAND_MENUS, get_menu_name, FALSE, TRUE}, | |
243 | ! {EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE}, | |
244 | #endif | |
245 | #ifdef FEAT_SYN_HL | |
246 | ! {EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE}, | |
247 | #endif | |
248 | ! {EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE}, | |
249 | #ifdef FEAT_AUTOCMD | |
250 | ! {EXPAND_EVENTS, get_event_name, TRUE, TRUE}, | |
251 | ! {EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE}, | |
252 | #endif | |
253 | #ifdef FEAT_CSCOPE | |
254 | ! {EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE}, | |
255 | #endif | |
256 | #ifdef FEAT_SIGNS | |
257 | ! {EXPAND_SIGN, get_sign_name, TRUE, TRUE}, | |
258 | #endif | |
259 | #ifdef FEAT_PROFILE | |
260 | ! {EXPAND_PROFILE, get_profile_name, TRUE, TRUE}, | |
261 | #endif | |
262 | #if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \ | |
263 | && (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE)) | |
264 | ! {EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE}, | |
265 | ! {EXPAND_LOCALES, get_locales, TRUE, FALSE}, | |
266 | #endif | |
267 | ! {EXPAND_ENV_VARS, get_env_name, TRUE, TRUE}, | |
268 | }; | |
269 | int i; | |
270 | ||
271 | *************** | |
272 | *** 4626,4632 **** | |
273 | { | |
274 | if (tab[i].ic) | |
275 | regmatch.rm_ic = TRUE; | |
276 | ! ret = ExpandGeneric(xp, ®match, num_file, file, tab[i].func); | |
277 | break; | |
278 | } | |
279 | } | |
280 | --- 4628,4635 ---- | |
281 | { | |
282 | if (tab[i].ic) | |
283 | regmatch.rm_ic = TRUE; | |
284 | ! ret = ExpandGeneric(xp, ®match, num_file, file, | |
285 | ! tab[i].func, tab[i].escaped); | |
286 | break; | |
287 | } | |
288 | } | |
289 | *************** | |
290 | *** 4648,4660 **** | |
291 | * Returns OK when no problems encountered, FAIL for error (out of memory). | |
292 | */ | |
293 | int | |
294 | ! ExpandGeneric(xp, regmatch, num_file, file, func) | |
295 | expand_T *xp; | |
296 | regmatch_T *regmatch; | |
297 | int *num_file; | |
298 | char_u ***file; | |
299 | char_u *((*func)__ARGS((expand_T *, int))); | |
300 | /* returns a string from the list */ | |
301 | { | |
302 | int i; | |
303 | int count = 0; | |
304 | --- 4651,4664 ---- | |
305 | * Returns OK when no problems encountered, FAIL for error (out of memory). | |
306 | */ | |
307 | int | |
308 | ! ExpandGeneric(xp, regmatch, num_file, file, func, escaped) | |
309 | expand_T *xp; | |
310 | regmatch_T *regmatch; | |
311 | int *num_file; | |
312 | char_u ***file; | |
313 | char_u *((*func)__ARGS((expand_T *, int))); | |
314 | /* returns a string from the list */ | |
315 | + int escaped; | |
316 | { | |
317 | int i; | |
318 | int count = 0; | |
319 | *************** | |
320 | *** 4679,4685 **** | |
321 | { | |
322 | if (round) | |
323 | { | |
324 | ! str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
325 | (*file)[count] = str; | |
326 | #ifdef FEAT_MENU | |
327 | if (func == get_menu_names && str != NULL) | |
328 | --- 4683,4692 ---- | |
329 | { | |
330 | if (round) | |
331 | { | |
332 | ! if (escaped) | |
333 | ! str = vim_strsave_escaped(str, (char_u *)" \t\\."); | |
334 | ! else | |
335 | ! str = vim_strsave(str); | |
336 | (*file)[count] = str; | |
337 | #ifdef FEAT_MENU | |
338 | if (func == get_menu_names && str != NULL) | |
339 | *** ../mercurial/vim73/src/proto/ex_cmds2.pro 2010-05-15 21:22:11.000000000 +0200 | |
340 | --- src/proto/ex_cmds2.pro 2011-05-19 17:53:52.000000000 +0200 | |
341 | *************** | |
342 | *** 83,87 **** | |
343 | --- 83,89 ---- | |
344 | char_u *get_mess_lang __ARGS((void)); | |
345 | void set_lang_var __ARGS((void)); | |
346 | void ex_language __ARGS((exarg_T *eap)); | |
347 | + void free_locales __ARGS((void)); | |
348 | char_u *get_lang_arg __ARGS((expand_T *xp, int idx)); | |
349 | + char_u *get_locales __ARGS((expand_T *xp, int idx)); | |
350 | /* vim: set ft=c : */ | |
351 | *** ../mercurial/vim73/src/proto/ex_getln.pro 2010-08-16 21:23:30.000000000 +0200 | |
352 | --- src/proto/ex_getln.pro 2011-05-19 17:54:00.000000000 +0200 | |
353 | *************** | |
354 | *** 31,37 **** | |
355 | char_u *addstar __ARGS((char_u *fname, int len, int context)); | |
356 | void set_cmd_context __ARGS((expand_T *xp, char_u *str, int len, int col)); | |
357 | int expand_cmdline __ARGS((expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches)); | |
358 | ! int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)))); | |
359 | char_u *globpath __ARGS((char_u *path, char_u *file, int expand_options)); | |
360 | void init_history __ARGS((void)); | |
361 | int get_histtype __ARGS((char_u *name)); | |
362 | --- 31,37 ---- | |
363 | char_u *addstar __ARGS((char_u *fname, int len, int context)); | |
364 | void set_cmd_context __ARGS((expand_T *xp, char_u *str, int len, int col)); | |
365 | int expand_cmdline __ARGS((expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches)); | |
366 | ! int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)), int escaped)); | |
367 | char_u *globpath __ARGS((char_u *path, char_u *file, int expand_options)); | |
368 | void init_history __ARGS((void)); | |
369 | int get_histtype __ARGS((char_u *name)); | |
370 | *** ../mercurial/vim73/src/vim.h 2011-05-19 17:25:36.000000000 +0200 | |
371 | --- src/vim.h 2011-05-19 17:52:02.000000000 +0200 | |
372 | *************** | |
373 | *** 779,784 **** | |
374 | --- 779,785 ---- | |
375 | #define EXPAND_FILETYPE 37 | |
376 | #define EXPAND_FILES_IN_PATH 38 | |
377 | #define EXPAND_OWNSYNTAX 39 | |
378 | + #define EXPAND_LOCALES 40 | |
379 | ||
380 | /* Values for exmode_active (0 is no exmode) */ | |
381 | #define EXMODE_NORMAL 1 | |
382 | *** ../vim-7.3.197/src/version.c 2011-05-19 17:42:54.000000000 +0200 | |
383 | --- src/version.c 2011-05-19 18:24:58.000000000 +0200 | |
384 | *************** | |
385 | *** 711,712 **** | |
386 | --- 711,714 ---- | |
387 | { /* Add new patch number below this line */ | |
388 | + /**/ | |
389 | + 198, | |
390 | /**/ | |
391 | ||
392 | -- | |
393 | The primary purpose of the DATA statement is to give names to constants; | |
394 | instead of referring to pi as 3.141592653589793 at every appearance, the | |
395 | variable PI can be given that value with a DATA statement and used instead | |
396 | of the longer form of the constant. This also simplifies modifying the | |
397 | program, should the value of pi change. | |
398 | -- FORTRAN manual for Xerox Computers | |
399 | ||
400 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
401 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
402 | \\\ an exciting new programming language -- http://www.Zimbu.org /// | |
403 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |