Skip to content

Commit df05321

Browse files
committed
updated for version 7.3.198
Problem: No completion for ":lang". Solution: Get locales to complete from. (Dominique Pelle)
1 parent 123bfb1 commit df05321

File tree

7 files changed

+134
-27
lines changed

7 files changed

+134
-27
lines changed

src/eval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,7 @@ eval_clear()
911911
hash_clear(&compat_hashtab);
912912

913913
free_scriptnames();
914+
free_locales();
914915

915916
/* global variables */
916917
vars_clear(&globvarht);

src/ex_cmds2.c

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ browse_save_fname(buf)
14761476
#endif
14771477

14781478
/*
1479-
* Ask the user what to do when abondoning a changed buffer.
1479+
* Ask the user what to do when abandoning a changed buffer.
14801480
* Must check 'write' option first!
14811481
*/
14821482
void
@@ -4153,6 +4153,82 @@ ex_language(eap)
41534153
}
41544154

41554155
# if defined(FEAT_CMDL_COMPL) || defined(PROTO)
4156+
4157+
static char_u **locales = NULL; /* Array of all available locales */
4158+
static int did_init_locales = FALSE;
4159+
4160+
static void init_locales __ARGS((void));
4161+
static char_u **find_locales __ARGS((void));
4162+
4163+
/*
4164+
* Lazy initialization of all available locales.
4165+
*/
4166+
static void
4167+
init_locales()
4168+
{
4169+
if (!did_init_locales)
4170+
{
4171+
did_init_locales = TRUE;
4172+
locales = find_locales();
4173+
}
4174+
}
4175+
4176+
/* Return an array of strings for all available locales + NULL for the
4177+
* last element. Return NULL in case of error. */
4178+
static char_u **
4179+
find_locales()
4180+
{
4181+
garray_T locales_ga;
4182+
char_u *loc;
4183+
4184+
/* Find all available locales by running command "locale -a". If this
4185+
* doesn't work we won't have completion. */
4186+
char_u *locale_a = get_cmd_output((char_u *)"locale -a",
4187+
NULL, SHELL_SILENT);
4188+
if (locale_a == NULL)
4189+
return NULL;
4190+
ga_init2(&locales_ga, sizeof(char_u *), 20);
4191+
4192+
/* Transform locale_a string where each locale is separated by "\n"
4193+
* into an array of locale strings. */
4194+
loc = (char_u *)strtok((char *)locale_a, "\n");
4195+
4196+
while (loc != NULL)
4197+
{
4198+
if (ga_grow(&locales_ga, 1) == FAIL)
4199+
break;
4200+
loc = vim_strsave(loc);
4201+
if (loc == NULL)
4202+
break;
4203+
4204+
((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc;
4205+
loc = (char_u *)strtok(NULL, "\n");
4206+
}
4207+
vim_free(locale_a);
4208+
if (ga_grow(&locales_ga, 1) == FAIL)
4209+
{
4210+
ga_clear(&locales_ga);
4211+
return NULL;
4212+
}
4213+
((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL;
4214+
return (char_u **)locales_ga.ga_data;
4215+
}
4216+
4217+
# if defined(EXITFREE) || defined(PROTO)
4218+
void
4219+
free_locales()
4220+
{
4221+
int i;
4222+
if (locales != NULL)
4223+
{
4224+
for (i = 0; locales[i] != NULL; i++)
4225+
vim_free(locales[i]);
4226+
vim_free(locales);
4227+
locales = NULL;
4228+
}
4229+
}
4230+
# endif
4231+
41564232
/*
41574233
* Function given to ExpandGeneric() to obtain the possible arguments of the
41584234
* ":language" command.
@@ -4168,7 +4244,25 @@ get_lang_arg(xp, idx)
41684244
return (char_u *)"ctype";
41694245
if (idx == 2)
41704246
return (char_u *)"time";
4171-
return NULL;
4247+
4248+
init_locales();
4249+
if (locales == NULL)
4250+
return NULL;
4251+
return locales[idx - 3];
4252+
}
4253+
4254+
/*
4255+
* Function given to ExpandGeneric() to obtain the available locales.
4256+
*/
4257+
char_u *
4258+
get_locales(xp, idx)
4259+
expand_T *xp UNUSED;
4260+
int idx;
4261+
{
4262+
init_locales();
4263+
if (locales == NULL)
4264+
return NULL;
4265+
return locales[idx];
41724266
}
41734267
# endif
41744268

src/ex_getln.c

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,48 +4571,50 @@ ExpandFromContext(xp, pat, num_file, file, options)
45714571
int context;
45724572
char_u *((*func)__ARGS((expand_T *, int)));
45734573
int ic;
4574+
int escaped;
45744575
} tab[] =
45754576
{
4576-
{EXPAND_COMMANDS, get_command_name, FALSE},
4577-
{EXPAND_BEHAVE, get_behave_arg, TRUE},
4577+
{EXPAND_COMMANDS, get_command_name, FALSE, TRUE},
4578+
{EXPAND_BEHAVE, get_behave_arg, TRUE, TRUE},
45784579
#ifdef FEAT_USR_CMDS
4579-
{EXPAND_USER_COMMANDS, get_user_commands, FALSE},
4580-
{EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE},
4581-
{EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE},
4582-
{EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE},
4580+
{EXPAND_USER_COMMANDS, get_user_commands, FALSE, TRUE},
4581+
{EXPAND_USER_CMD_FLAGS, get_user_cmd_flags, FALSE, TRUE},
4582+
{EXPAND_USER_NARGS, get_user_cmd_nargs, FALSE, TRUE},
4583+
{EXPAND_USER_COMPLETE, get_user_cmd_complete, FALSE, TRUE},
45834584
#endif
45844585
#ifdef FEAT_EVAL
4585-
{EXPAND_USER_VARS, get_user_var_name, FALSE},
4586-
{EXPAND_FUNCTIONS, get_function_name, FALSE},
4587-
{EXPAND_USER_FUNC, get_user_func_name, FALSE},
4588-
{EXPAND_EXPRESSION, get_expr_name, FALSE},
4586+
{EXPAND_USER_VARS, get_user_var_name, FALSE, TRUE},
4587+
{EXPAND_FUNCTIONS, get_function_name, FALSE, TRUE},
4588+
{EXPAND_USER_FUNC, get_user_func_name, FALSE, TRUE},
4589+
{EXPAND_EXPRESSION, get_expr_name, FALSE, TRUE},
45894590
#endif
45904591
#ifdef FEAT_MENU
4591-
{EXPAND_MENUS, get_menu_name, FALSE},
4592-
{EXPAND_MENUNAMES, get_menu_names, FALSE},
4592+
{EXPAND_MENUS, get_menu_name, FALSE, TRUE},
4593+
{EXPAND_MENUNAMES, get_menu_names, FALSE, TRUE},
45934594
#endif
45944595
#ifdef FEAT_SYN_HL
4595-
{EXPAND_SYNTAX, get_syntax_name, TRUE},
4596+
{EXPAND_SYNTAX, get_syntax_name, TRUE, TRUE},
45964597
#endif
4597-
{EXPAND_HIGHLIGHT, get_highlight_name, TRUE},
4598+
{EXPAND_HIGHLIGHT, get_highlight_name, TRUE, TRUE},
45984599
#ifdef FEAT_AUTOCMD
4599-
{EXPAND_EVENTS, get_event_name, TRUE},
4600-
{EXPAND_AUGROUP, get_augroup_name, TRUE},
4600+
{EXPAND_EVENTS, get_event_name, TRUE, TRUE},
4601+
{EXPAND_AUGROUP, get_augroup_name, TRUE, TRUE},
46014602
#endif
46024603
#ifdef FEAT_CSCOPE
4603-
{EXPAND_CSCOPE, get_cscope_name, TRUE},
4604+
{EXPAND_CSCOPE, get_cscope_name, TRUE, TRUE},
46044605
#endif
46054606
#ifdef FEAT_SIGNS
4606-
{EXPAND_SIGN, get_sign_name, TRUE},
4607+
{EXPAND_SIGN, get_sign_name, TRUE, TRUE},
46074608
#endif
46084609
#ifdef FEAT_PROFILE
4609-
{EXPAND_PROFILE, get_profile_name, TRUE},
4610+
{EXPAND_PROFILE, get_profile_name, TRUE, TRUE},
46104611
#endif
46114612
#if (defined(HAVE_LOCALE_H) || defined(X_LOCALE)) \
46124613
&& (defined(FEAT_GETTEXT) || defined(FEAT_MBYTE))
4613-
{EXPAND_LANGUAGE, get_lang_arg, TRUE},
4614+
{EXPAND_LANGUAGE, get_lang_arg, TRUE, FALSE},
4615+
{EXPAND_LOCALES, get_locales, TRUE, FALSE},
46144616
#endif
4615-
{EXPAND_ENV_VARS, get_env_name, TRUE},
4617+
{EXPAND_ENV_VARS, get_env_name, TRUE, TRUE},
46164618
};
46174619
int i;
46184620

@@ -4626,7 +4628,8 @@ ExpandFromContext(xp, pat, num_file, file, options)
46264628
{
46274629
if (tab[i].ic)
46284630
regmatch.rm_ic = TRUE;
4629-
ret = ExpandGeneric(xp, &regmatch, num_file, file, tab[i].func);
4631+
ret = ExpandGeneric(xp, &regmatch, num_file, file,
4632+
tab[i].func, tab[i].escaped);
46304633
break;
46314634
}
46324635
}
@@ -4648,13 +4651,14 @@ ExpandFromContext(xp, pat, num_file, file, options)
46484651
* Returns OK when no problems encountered, FAIL for error (out of memory).
46494652
*/
46504653
int
4651-
ExpandGeneric(xp, regmatch, num_file, file, func)
4654+
ExpandGeneric(xp, regmatch, num_file, file, func, escaped)
46524655
expand_T *xp;
46534656
regmatch_T *regmatch;
46544657
int *num_file;
46554658
char_u ***file;
46564659
char_u *((*func)__ARGS((expand_T *, int)));
46574660
/* returns a string from the list */
4661+
int escaped;
46584662
{
46594663
int i;
46604664
int count = 0;
@@ -4679,7 +4683,10 @@ ExpandGeneric(xp, regmatch, num_file, file, func)
46794683
{
46804684
if (round)
46814685
{
4682-
str = vim_strsave_escaped(str, (char_u *)" \t\\.");
4686+
if (escaped)
4687+
str = vim_strsave_escaped(str, (char_u *)" \t\\.");
4688+
else
4689+
str = vim_strsave(str);
46834690
(*file)[count] = str;
46844691
#ifdef FEAT_MENU
46854692
if (func == get_menu_names && str != NULL)

src/proto/ex_cmds2.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,7 @@ void ex_checktime __ARGS((exarg_T *eap));
8383
char_u *get_mess_lang __ARGS((void));
8484
void set_lang_var __ARGS((void));
8585
void ex_language __ARGS((exarg_T *eap));
86+
void free_locales __ARGS((void));
8687
char_u *get_lang_arg __ARGS((expand_T *xp, int idx));
88+
char_u *get_locales __ARGS((expand_T *xp, int idx));
8789
/* vim: set ft=c : */

src/proto/ex_getln.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ char_u *sm_gettail __ARGS((char_u *s));
3131
char_u *addstar __ARGS((char_u *fname, int len, int context));
3232
void set_cmd_context __ARGS((expand_T *xp, char_u *str, int len, int col));
3333
int expand_cmdline __ARGS((expand_T *xp, char_u *str, int col, int *matchcount, char_u ***matches));
34-
int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int))));
34+
int ExpandGeneric __ARGS((expand_T *xp, regmatch_T *regmatch, int *num_file, char_u ***file, char_u *((*func)(expand_T *, int)), int escaped));
3535
char_u *globpath __ARGS((char_u *path, char_u *file, int expand_options));
3636
void init_history __ARGS((void));
3737
int get_histtype __ARGS((char_u *name));

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,8 @@ static char *(features[]) =
709709

710710
static int included_patches[] =
711711
{ /* Add new patch number below this line */
712+
/**/
713+
198,
712714
/**/
713715
197,
714716
/**/

src/vim.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,7 @@ extern char *(*dyn_libintl_textdomain)(const char *domainname);
779779
#define EXPAND_FILETYPE 37
780780
#define EXPAND_FILES_IN_PATH 38
781781
#define EXPAND_OWNSYNTAX 39
782+
#define EXPAND_LOCALES 40
782783

783784
/* Values for exmode_active (0 is no exmode) */
784785
#define EXMODE_NORMAL 1

0 commit comments

Comments
 (0)