mirror of
https://github.com/neovim/neovim.git
synced 2025-09-19 09:48:19 +00:00
eval: port v:collate
Cherry-picked from patch v8.2.0988. Required for patch v8.2.1933.
This commit is contained in:
@@ -1495,6 +1495,15 @@ v:cmdarg This variable is used for two purposes:
|
||||
the argument for the ":hardcopy" command. This can be used
|
||||
in 'printexpr'.
|
||||
|
||||
*v:collate* *collate-variable*
|
||||
v:collate The current locale setting for collation order of the runtime
|
||||
environment. This allows Vim scripts to be aware of the
|
||||
current locale encoding. Technical: it's the value of
|
||||
LC_COLLATE. When not using a locale the value is "C".
|
||||
This variable can not be set directly, use the |:language|
|
||||
command.
|
||||
See |multi-lang|.
|
||||
|
||||
*v:cmdbang* *cmdbang-variable*
|
||||
v:cmdbang Set like v:cmdarg for a file read/write command. When a "!"
|
||||
was used the value is 1, otherwise it is 0. Note that this
|
||||
|
@@ -31,6 +31,7 @@ use of "-" and "_".
|
||||
:lan[guage] mes[sages]
|
||||
:lan[guage] cty[pe]
|
||||
:lan[guage] tim[e]
|
||||
:lan[guage] col[late]
|
||||
Print the current language (aka locale).
|
||||
With the "messages" argument the language used for
|
||||
messages is printed. Technical: LC_MESSAGES.
|
||||
@@ -38,15 +39,19 @@ use of "-" and "_".
|
||||
character encoding is printed. Technical: LC_CTYPE.
|
||||
With the "time" argument the language used for
|
||||
strftime() is printed. Technical: LC_TIME.
|
||||
With the "collate" argument the language used for
|
||||
collation order is printed. Technical: LC_COLLATE.
|
||||
Without argument all parts of the locale are printed
|
||||
(this is system dependent).
|
||||
The current language can also be obtained with the
|
||||
|v:lang|, |v:ctype| and |v:lc_time| variables.
|
||||
|v:lang|, |v:ctype|, |v:collate| and |v:lc_time|
|
||||
variables.
|
||||
|
||||
:lan[guage] {name}
|
||||
:lan[guage] mes[sages] {name}
|
||||
:lan[guage] cty[pe] {name}
|
||||
:lan[guage] tim[e] {name}
|
||||
:lan[guage] col[late] {name}
|
||||
Set the current language (aka locale) to {name}.
|
||||
The locale {name} must be a valid locale on your
|
||||
system. Some systems accept aliases like "en" or
|
||||
@@ -66,7 +71,10 @@ use of "-" and "_".
|
||||
With the "time" argument the language used for time
|
||||
and date messages is set. This affects strftime().
|
||||
This sets $LC_TIME.
|
||||
Without an argument both are set, and additionally
|
||||
With the "collate" argument the language used for the
|
||||
collation order is set. This affects sorting of
|
||||
characters. This sets $LC_COLLATE.
|
||||
Without an argument all are set, and additionally
|
||||
$LANG is set.
|
||||
The LC_NUMERIC value will always be set to "C" so
|
||||
that floating point numbers use '.' as the decimal
|
||||
|
@@ -225,6 +225,7 @@ static struct vimvar {
|
||||
VV(VV_EVENT, "event", VAR_DICT, VV_RO),
|
||||
VV(VV_ECHOSPACE, "echospace", VAR_NUMBER, VV_RO),
|
||||
VV(VV_ARGV, "argv", VAR_LIST, VV_RO),
|
||||
VV(VV_COLLATE, "collate", VAR_STRING, VV_RO),
|
||||
VV(VV_EXITING, "exiting", VAR_NUMBER, VV_RO),
|
||||
// Neovim
|
||||
VV(VV_STDERR, "stderr", VAR_NUMBER, VV_RO),
|
||||
|
@@ -154,6 +154,7 @@ typedef enum {
|
||||
VV_EVENT,
|
||||
VV_ECHOSPACE,
|
||||
VV_ARGV,
|
||||
VV_COLLATE,
|
||||
VV_EXITING,
|
||||
// Neovim
|
||||
VV_STDERR,
|
||||
|
@@ -3627,6 +3627,14 @@ void set_lang_var(void)
|
||||
loc = get_locale_val(LC_TIME);
|
||||
# endif
|
||||
set_vim_var_string(VV_LC_TIME, loc, -1);
|
||||
|
||||
# ifdef HAVE_GET_LOCALE_VAL
|
||||
loc = get_locale_val(LC_COLLATE);
|
||||
# else
|
||||
// setlocale() not supported: use the default value
|
||||
loc = "C";
|
||||
# endif
|
||||
set_vim_var_string(VV_COLLATE, loc, -1);
|
||||
}
|
||||
|
||||
#ifdef HAVE_WORKING_LIBINTL
|
||||
@@ -3667,6 +3675,10 @@ void ex_language(exarg_T *eap)
|
||||
what = LC_TIME;
|
||||
name = skipwhite(p);
|
||||
whatstr = "time ";
|
||||
} else if (STRNICMP(eap->arg, "collate", p - eap->arg) == 0) {
|
||||
what = LC_COLLATE;
|
||||
name = skipwhite(p);
|
||||
whatstr = "collate ";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3711,7 +3723,7 @@ void ex_language(exarg_T *eap)
|
||||
// Reset $LC_ALL, otherwise it would overrule everything.
|
||||
os_setenv("LC_ALL", "", 1);
|
||||
|
||||
if (what != LC_TIME) {
|
||||
if (what != LC_TIME && what != LC_COLLATE) {
|
||||
// Tell gettext() what to translate to. It apparently doesn't
|
||||
// use the currently effective locale.
|
||||
if (what == LC_ALL) {
|
||||
@@ -3726,7 +3738,7 @@ void ex_language(exarg_T *eap)
|
||||
}
|
||||
}
|
||||
|
||||
// Set v:lang, v:lc_time and v:ctype to the final result.
|
||||
// Set v:lang, v:lc_time, v:collate and v:ctype to the final result.
|
||||
set_lang_var();
|
||||
maketitle();
|
||||
}
|
||||
@@ -3811,12 +3823,15 @@ char_u *get_lang_arg(expand_T *xp, int idx)
|
||||
if (idx == 2) {
|
||||
return (char_u *)"time";
|
||||
}
|
||||
if (idx == 3) {
|
||||
return (char_u *)"collate";
|
||||
}
|
||||
|
||||
init_locales();
|
||||
if (locales == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return locales[idx - 3];
|
||||
return locales[idx - 4];
|
||||
}
|
||||
|
||||
/// Function given to ExpandGeneric() to obtain the available locales.
|
||||
|
@@ -3642,7 +3642,8 @@ const char * set_one_cmd_context(
|
||||
} else {
|
||||
if (strncmp(arg, "messages", p - arg) == 0
|
||||
|| strncmp(arg, "ctype", p - arg) == 0
|
||||
|| strncmp(arg, "time", p - arg) == 0) {
|
||||
|| strncmp(arg, "time", p - arg) == 0
|
||||
|| strncmp(arg, "collate", p - arg) == 0) {
|
||||
xp->xp_context = EXPAND_LOCALES;
|
||||
xp->xp_pattern = skipwhite((const char_u *)p);
|
||||
} else {
|
||||
|
@@ -615,10 +615,20 @@ func Test_cmdline_complete_bang()
|
||||
endfunc
|
||||
|
||||
funct Test_cmdline_complete_languages()
|
||||
let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
|
||||
call assert_equal(lang, v:lc_time)
|
||||
|
||||
let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
|
||||
call assert_equal(lang, v:ctype)
|
||||
|
||||
let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
|
||||
call assert_equal(lang, v:collate)
|
||||
|
||||
let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
|
||||
call assert_equal(lang, v:lang)
|
||||
|
||||
call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
|
||||
call assert_match('^"language .*\<ctype\>.*\<messages\>.*\<time\>', @:)
|
||||
call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
|
||||
|
||||
if has('unix')
|
||||
" TODO: these tests don't work on Windows. lang appears to be 'C'
|
||||
@@ -633,6 +643,9 @@ funct Test_cmdline_complete_languages()
|
||||
|
||||
call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
|
||||
call assert_match('^"language .*\<' . lang . '\>', @:)
|
||||
|
||||
call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
|
||||
call assert_match('^"language .*\<' . lang . '\>', @:)
|
||||
endif
|
||||
endfunc
|
||||
|
||||
|
Reference in New Issue
Block a user