aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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.
Diffstat (limited to 'src')
-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
5 files changed, 36 insertions, 5 deletions
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