From 1d72b6e4cd5807d27acce9b6f8b6d22176e50951 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 20 Apr 2021 00:01:50 +0100 Subject: eval: port v:collate Cherry-picked from patch v8.2.0988. Required for patch v8.2.1933. --- runtime/doc/eval.txt | 9 +++++++++ runtime/doc/mlang.txt | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'runtime') 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 -- cgit From 6a0b8cbd81f81957a415cf03415bf2bffc18b56e Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 19 Apr 2021 19:57:19 +0100 Subject: vim-patch:8.2.1933: cannot sort using locale ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Cannot sort using locale ordering. Solution: Add a flag for :sort and sort() to use the locale. (Dominique Pellé, closes vim/vim#7237) https://github.com/vim/vim/commit/55e29611d20bca14fa5efc61385bc8a6b7acd9e2 --- runtime/doc/change.txt | 13 ++++++++++--- runtime/doc/eval.txt | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index 310d244fbc..bdef544b2a 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -1742,7 +1742,7 @@ Vim has a sorting function and a sorting command. The sorting function can be found here: |sort()|, |uniq()|. *:sor* *:sort* -:[range]sor[t][!] [b][f][i][n][o][r][u][x] [/{pattern}/] +:[range]sor[t][!] [b][f][i][l][n][o][r][u][x] [/{pattern}/] Sort lines in [range]. When no range is given all lines are sorted. @@ -1750,6 +1750,14 @@ found here: |sort()|, |uniq()|. With [i] case is ignored. + With [l] sort uses the current locale. See + `language collate` to check or set the locale used + for ordering. For example, with "en_US.UTF8", + Ö will be ordered after O and before P, + whereas with the Swedish locale "sv_SE.UTF8", + it will be after Z. + Case is typically ignored by the locale. + Options [n][f][x][o][b] are mutually exclusive. With [n] sorting is done on the first decimal number @@ -1816,8 +1824,7 @@ found here: |sort()|, |uniq()|. Note that using `:sort` with `:global` doesn't sort the matching lines, it's quite useless. -The details about sorting depend on the library function used. There is no -guarantee that sorting obeys the current locale. You will have to try it out. +`:sort` does not use the current locale unless the l flag is used. Vim does do a "stable" sort. The sorting can be interrupted, but if you interrupt it too late in the diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 01803041a8..2aff9fc127 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -8359,6 +8359,13 @@ sort({list} [, {func} [, {dict}]]) *sort()* *E702* When {func} is given and it is '1' or 'i' then case is ignored. + When {func} is given and it is 'l' then the current locale + is used for ordering. See `language collate` to check or set + the locale used for ordering. For example, with "en_US.UTF8", + Ö will be ordered after O and before P, whereas with the + Swedish locale "sv_SE.UTF8", it will be after Z. + Case is typically ignored by the locale. + When {func} is given and it is 'n' then all items will be sorted numerical (Implementation detail: This uses the strtod() function to parse numbers, Strings, Lists, Dicts and -- cgit From eef5a627bfc4341fdd6f12ea5932d11b12fbf2c0 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Tue, 20 Apr 2021 01:39:19 +0100 Subject: doc: port changes for locale-based :sort Cherry-picked from https://github.com/vim/vim/commit/3132cddd209ee510bde48b6520290cb26c8f604a. --- runtime/doc/change.txt | 16 +++++++++------- runtime/doc/eval.txt | 24 +++++++++++++++++------- 2 files changed, 26 insertions(+), 14 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt index bdef544b2a..e353f3d209 100644 --- a/runtime/doc/change.txt +++ b/runtime/doc/change.txt @@ -1750,13 +1750,15 @@ found here: |sort()|, |uniq()|. With [i] case is ignored. - With [l] sort uses the current locale. See - `language collate` to check or set the locale used - for ordering. For example, with "en_US.UTF8", - Ö will be ordered after O and before P, - whereas with the Swedish locale "sv_SE.UTF8", - it will be after Z. - Case is typically ignored by the locale. + With [l] sort uses the current collation locale. + Implementation details: strcoll() is used to compare + strings. See |:language| to check or set the collation + locale. Example: > + :language collate en_US.UTF-8 + :%sort l +< |v:collate| can also used to check the current locale. + Sorting using the locale typically ignores case. + This does not work properly on Mac. Options [n][f][x][o][b] are mutually exclusive. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 2aff9fc127..98f702af4c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -8359,15 +8359,25 @@ sort({list} [, {func} [, {dict}]]) *sort()* *E702* When {func} is given and it is '1' or 'i' then case is ignored. - When {func} is given and it is 'l' then the current locale - is used for ordering. See `language collate` to check or set - the locale used for ordering. For example, with "en_US.UTF8", - Ö will be ordered after O and before P, whereas with the - Swedish locale "sv_SE.UTF8", it will be after Z. - Case is typically ignored by the locale. + When {func} is given and it is 'l' then the current collation + locale is used for ordering. Implementation details: strcoll() + is used to compare strings. See |:language| check or set the + collation locale. |v:collate| can also be used to check the + current locale. Sorting using the locale typically ignores + case. Example: > + " ö is sorted similarly to o with English locale. + :language collate en_US.UTF8 + :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') +< ['n', 'o', 'O', 'ö', 'p', 'z'] ~ +> + " ö is sorted after z with Swedish locale. + :language collate sv_SE.UTF8 + :echo sort(['n', 'o', 'O', 'ö', 'p', 'z'], 'l') +< ['n', 'o', 'O', 'p', 'z', 'ö'] ~ + This does not work properly on Mac. When {func} is given and it is 'n' then all items will be - sorted numerical (Implementation detail: This uses the + sorted numerical (Implementation detail: this uses the strtod() function to parse numbers, Strings, Lists, Dicts and Funcrefs will be considered as being 0). -- cgit