aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-04-20 00:01:50 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-04-20 02:03:46 +0100
commit1d72b6e4cd5807d27acce9b6f8b6d22176e50951 (patch)
tree7c2329f263f6f13624954c30ea296af2f3e91c84
parent96f62394cfc74e731529ed68039aa8da1facdf13 (diff)
downloadrneovim-1d72b6e4cd5807d27acce9b6f8b6d22176e50951.tar.gz
rneovim-1d72b6e4cd5807d27acce9b6f8b6d22176e50951.tar.bz2
rneovim-1d72b6e4cd5807d27acce9b6f8b6d22176e50951.zip
eval: port v:collate
Cherry-picked from patch v8.2.0988. Required for patch v8.2.1933.
-rw-r--r--runtime/doc/eval.txt9
-rw-r--r--runtime/doc/mlang.txt12
-rw-r--r--src/nvim/eval.c1
-rw-r--r--src/nvim/eval.h1
-rw-r--r--src/nvim/ex_cmds2.c21
-rw-r--r--src/nvim/ex_docmd.c3
-rw-r--r--src/nvim/testdir/test_cmdline.vim15
7 files changed, 55 insertions, 7 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index cff87b2fed..01803041a8 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -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
diff --git a/runtime/doc/mlang.txt b/runtime/doc/mlang.txt
index 5217b2c160..7ed574d9b8 100644
--- a/runtime/doc/mlang.txt
+++ b/runtime/doc/mlang.txt
@@ -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
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 05d429c7d5..370ffd152e 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -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),
diff --git a/src/nvim/eval.h b/src/nvim/eval.h
index 3da4bb8655..ef5f90ed8f 100644
--- a/src/nvim/eval.h
+++ b/src/nvim/eval.h
@@ -154,6 +154,7 @@ typedef enum {
VV_EVENT,
VV_ECHOSPACE,
VV_ARGV,
+ VV_COLLATE,
VV_EXITING,
// Neovim
VV_STDERR,
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index 950a1a436f..2821074b0d 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -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.
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index ae5c334592..555029c1fb 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -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 {
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index 489b2477e6..a1968807ac 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -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