mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.0961: MS-Windows: no completion for locales
Problem: MS-Windows: no completion for locales. Solution: Use the directories in $VIMRUNTIME/lang to complete locales. (Christian Brabandt, closes 36248)
This commit is contained in:
parent
9721fb4ea3
commit
ec68028604
@ -273,6 +273,7 @@ nextwild(
|
||||
* options = WILD_SILENT: don't print warning messages
|
||||
* options = WILD_ESCAPE: put backslash before special chars
|
||||
* options = WILD_ICASE: ignore case for files
|
||||
* options = WILD_ALLLINKS; keep broken links
|
||||
*
|
||||
* The variables xp->xp_context and xp->xp_backslash must have been set!
|
||||
*/
|
||||
|
@ -1188,7 +1188,7 @@ set_lang_var(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE) \
|
||||
#if defined(HAVE_LOCALE_H) || defined(X_LOCALE)
|
||||
/*
|
||||
* ":language": Set the language (locale).
|
||||
*/
|
||||
@ -1321,7 +1321,6 @@ ex_language(exarg_T *eap)
|
||||
|
||||
static char_u **locales = NULL; // Array of all available locales
|
||||
|
||||
# ifndef MSWIN
|
||||
static int did_init_locales = FALSE;
|
||||
|
||||
/*
|
||||
@ -1333,31 +1332,87 @@ find_locales(void)
|
||||
{
|
||||
garray_T locales_ga;
|
||||
char_u *loc;
|
||||
char_u *locale_list;
|
||||
# ifdef MSWIN
|
||||
size_t len = 0;
|
||||
# endif
|
||||
|
||||
// Find all available locales by running command "locale -a". If this
|
||||
// doesn't work we won't have completion.
|
||||
char_u *locale_a = get_cmd_output((char_u *)"locale -a",
|
||||
# ifndef MSWIN
|
||||
locale_list = get_cmd_output((char_u *)"locale -a",
|
||||
NULL, SHELL_SILENT, NULL);
|
||||
if (locale_a == NULL)
|
||||
# else
|
||||
// Find all available locales by examining the directories in
|
||||
// $VIMRUNTIME/lang/
|
||||
{
|
||||
int options = WILD_SILENT|WILD_USE_NL|WILD_KEEP_ALL;
|
||||
expand_T xpc;
|
||||
char_u *p;
|
||||
|
||||
ExpandInit(&xpc);
|
||||
xpc.xp_context = EXPAND_DIRECTORIES;
|
||||
locale_list = ExpandOne(&xpc, (char_u *)"$VIMRUNTIME/lang/*",
|
||||
NULL, options, WILD_ALL);
|
||||
ExpandCleanup(&xpc);
|
||||
if (locale_list == NULL)
|
||||
// Add a dummy input, that will be skipped lated but we need to
|
||||
// have something in locale_list so that the C locale is added at
|
||||
// the end.
|
||||
locale_list = vim_strsave((char_u *)".\n");
|
||||
p = locale_list;
|
||||
// find the last directory delimiter
|
||||
while (p != NULL && *p != NUL)
|
||||
{
|
||||
if (*p == '\n')
|
||||
break;
|
||||
if (*p == '\\')
|
||||
len = p - locale_list;
|
||||
p++;
|
||||
}
|
||||
}
|
||||
# endif
|
||||
if (locale_list == NULL)
|
||||
return NULL;
|
||||
ga_init2(&locales_ga, sizeof(char_u *), 20);
|
||||
|
||||
// Transform locale_a string where each locale is separated by "\n"
|
||||
// Transform locale_list string where each locale is separated by "\n"
|
||||
// into an array of locale strings.
|
||||
loc = (char_u *)strtok((char *)locale_a, "\n");
|
||||
loc = (char_u *)strtok((char *)locale_list, "\n");
|
||||
|
||||
while (loc != NULL)
|
||||
{
|
||||
int ignore = FALSE;
|
||||
|
||||
# ifdef MSWIN
|
||||
if (len > 0)
|
||||
loc += len + 1;
|
||||
// skip locales with a dot (which indicates the charset)
|
||||
if (vim_strchr(loc, '.') != NULL)
|
||||
ignore = TRUE;
|
||||
# endif
|
||||
if (!ignore)
|
||||
{
|
||||
if (ga_grow(&locales_ga, 1) == FAIL)
|
||||
break;
|
||||
|
||||
loc = vim_strsave(loc);
|
||||
if (loc == NULL)
|
||||
break;
|
||||
|
||||
((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] = loc;
|
||||
}
|
||||
loc = (char_u *)strtok(NULL, "\n");
|
||||
}
|
||||
vim_free(locale_a);
|
||||
|
||||
# ifdef MSWIN
|
||||
// Add the C locale
|
||||
if (ga_grow(&locales_ga, 1) == OK)
|
||||
((char_u **)locales_ga.ga_data)[locales_ga.ga_len++] =
|
||||
vim_strsave((char_u *)"C");
|
||||
# endif
|
||||
|
||||
vim_free(locale_list);
|
||||
if (ga_grow(&locales_ga, 1) == FAIL)
|
||||
{
|
||||
ga_clear(&locales_ga);
|
||||
@ -1366,7 +1421,6 @@ find_locales(void)
|
||||
((char_u **)locales_ga.ga_data)[locales_ga.ga_len] = NULL;
|
||||
return (char_u **)locales_ga.ga_data;
|
||||
}
|
||||
# endif
|
||||
|
||||
/*
|
||||
* Lazy initialization of all available locales.
|
||||
@ -1374,13 +1428,11 @@ find_locales(void)
|
||||
static void
|
||||
init_locales(void)
|
||||
{
|
||||
# ifndef MSWIN
|
||||
if (!did_init_locales)
|
||||
{
|
||||
did_init_locales = TRUE;
|
||||
locales = find_locales();
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
# if defined(EXITFREE) || defined(PROTO)
|
||||
|
@ -609,9 +609,6 @@ func Test_cmdline_complete_languages()
|
||||
call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
|
||||
call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:)
|
||||
|
||||
if has('unix')
|
||||
" TODO: these tests don't work on Windows. lang appears to be 'C'
|
||||
" but C does not appear in the completion. Why?
|
||||
call assert_match('^"language .*\<' . lang . '\>', @:)
|
||||
|
||||
call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
|
||||
@ -622,7 +619,6 @@ func Test_cmdline_complete_languages()
|
||||
|
||||
call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
|
||||
call assert_match('^"language .*\<' . lang . '\>', @:)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
func Test_cmdline_complete_env_variable()
|
||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
961,
|
||||
/**/
|
||||
960,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user