the :sort command does not appear to give expected result

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

the :sort command does not appear to give expected result

Chris Jones-44
Here's a (test) file that contains a sample of single characters from
the French alphabet.

Column 1 contains a <tab> character (0x09) and column 2 contains the
actual letters.

        A
        E
        O
        À
        È
        É
        Ô
        Œ

If I use the sort command provided on linux by the GNU coreutils package
so as to sort this file at the terminal with the following locale:

  LANG=en_US.UTF-8
  LANGUAGE=
  LC_CTYPE="en_US.UTF-8"
  LC_NUMERIC="en_US.UTF-8"
  LC_TIME="en_US.UTF-8"
  LC_COLLATE="en_US.UTF-8"
  LC_MONETARY="en_US.UTF-8"
  LC_MESSAGES="en_US.UTF-8"
  LC_PAPER="en_US.UTF-8"
  LC_NAME="en_US.UTF-8"
  LC_ADDRESS="en_US.UTF-8"
  LC_TELEPHONE="en_US.UTF-8"
  LC_MEASUREMENT="en_US.UTF-8"
  LC_IDENTIFICATION="en_US.UTF-8"
  LC_ALL=

... without changing locales the resulting ouput appears to be
sorted the way it should be:

        A
        À
        E
        É
        È
        O
        Ô
        Œ

But when I edit the file in vim and run the :sort / / where the '//'
pattern contains a tab character (0x09) nothing happens.

In other words... the fancy pants letters (À, È, É, Ô, Œ ) stay where
they are instead of being moved to the spot where they belong.

So I tried launching vim like so:

  $ LANG='fr_FR.UTF-8' vim

I noticed that vim was now talking French to me and when I ran the
':language' commmand I saw that vim's locale-related variables were now
set to the 'fr_FR' locale:

Langue courante pour  :

  "LC_CTYPE=fr_FR.UTF-8;
   LC_NUMERIC=C;
   LC_TIME=fr_FR.UTF-8;
   LC_COLLATE=fr_FR.UTF-8;
   LC_MONETARY=fr_FR.UTF-8;
   LC_MESSAGES=fr_FR.UTF-8;
   LC_PAPER=fr_FR.UTF-8;
   LC_NAME=fr_FR.UTF-8;
   LC_ADDRESS=fr_FR.UTF-8;
   LC_TELEPHONE=fr_FR.UTF-8;
   LC_MEASUREMENT=fr_FR.UTF-8;
   LC_IDENTIFICATION=fr_FR.UTF-8"

But when I ran the same ':sort / /' command it didn't make any difference.

Am I doing it wrong?

Thanks,

CJ

P.S. I'm using a bit of vim trickery to translate the LaTeX '\index ...'
etc. stuff to html tags so as to have a basic index with links to
anchors in the HTML version of the document. Unfortunately the original
document happens to be in French... and naturally... correct sorting of
the 'TABLE ALPHABÉTIQUE' is crucial (I do want eggs/œufs to appear under
letter 'O'... not relegated to the index's last page).

I've read the ':h :sort' doc something like a dozen times and find parts
of it a little cryptic. Especially when somewhere near the end it says:
'Vim does do a "stable" sort.' :-) What's up with that?

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201027225540.GC5998%40turki.local.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Tony Mechelynck
On Tue, Oct 27, 2020 at 11:55 PM Chris Jones <[hidden email]> wrote:

>
> Here's a (test) file that contains a sample of single characters from
> the French alphabet.
>
> Column 1 contains a <tab> character (0x09) and column 2 contains the
> actual letters.
>
>         A
>         E
>         O
>         À
>         È
>         É
>         Ô
>         Œ
>
> If I use the sort command provided on linux by the GNU coreutils package
> so as to sort this file at the terminal with the following locale:
>
>   LANG=en_US.UTF-8
>   LANGUAGE=
>   LC_CTYPE="en_US.UTF-8"
>   LC_NUMERIC="en_US.UTF-8"
>   LC_TIME="en_US.UTF-8"
>   LC_COLLATE="en_US.UTF-8"
>   LC_MONETARY="en_US.UTF-8"
>   LC_MESSAGES="en_US.UTF-8"
>   LC_PAPER="en_US.UTF-8"
>   LC_NAME="en_US.UTF-8"
>   LC_ADDRESS="en_US.UTF-8"
>   LC_TELEPHONE="en_US.UTF-8"
>   LC_MEASUREMENT="en_US.UTF-8"
>   LC_IDENTIFICATION="en_US.UTF-8"
>   LC_ALL=
>
> ... without changing locales the resulting ouput appears to be
> sorted the way it should be:
>
>         A
>         À
>         E
>         É
>         È
>         O
>         Ô
>         Œ
>
> But when I edit the file in vim and run the :sort /     / where the '//'
> pattern contains a tab character (0x09) nothing happens.
>
> In other words... the fancy pants letters (À, È, É, Ô, Œ ) stay where
> they are instead of being moved to the spot where they belong.
>
> So I tried launching vim like so:
>
>   $ LANG='fr_FR.UTF-8' vim
>
> I noticed that vim was now talking French to me and when I ran the
> ':language' commmand I saw that vim's locale-related variables were now
> set to the 'fr_FR' locale:
>
> Langue courante pour  :
>
>   "LC_CTYPE=fr_FR.UTF-8;
>    LC_NUMERIC=C;
>    LC_TIME=fr_FR.UTF-8;
>    LC_COLLATE=fr_FR.UTF-8;
>    LC_MONETARY=fr_FR.UTF-8;
>    LC_MESSAGES=fr_FR.UTF-8;
>    LC_PAPER=fr_FR.UTF-8;
>    LC_NAME=fr_FR.UTF-8;
>    LC_ADDRESS=fr_FR.UTF-8;
>    LC_TELEPHONE=fr_FR.UTF-8;
>    LC_MEASUREMENT=fr_FR.UTF-8;
>    LC_IDENTIFICATION=fr_FR.UTF-8"
>
> But when I ran the same ':sort /        /' command it didn't make any difference.
>
> Am I doing it wrong?
>
> Thanks,
>
> CJ
>
> P.S. I'm using a bit of vim trickery to translate the LaTeX '\index ...'
> etc. stuff to html tags so as to have a basic index with links to
> anchors in the HTML version of the document. Unfortunately the original
> document happens to be in French... and naturally... correct sorting of
> the 'TABLE ALPHABÉTIQUE' is crucial (I do want eggs/œufs to appear under
> letter 'O'... not relegated to the index's last page).
>
> I've read the ':h :sort' doc something like a dozen times and find parts
> of it a little cryptic. Especially when somewhere near the end it says:
> 'Vim does do a "stable" sort.' :-) What's up with that?

A "stable" sort is a sort which will keep lines with the same sort
keys in the order they were before the sort. (If you sort on whole
lines the difference is not visible, unless there exist different
lines which sort as equal, but if you sort on "pattern" or on "first
number" it may matter.)

But there is another few sentences which may be relevant in the help
for :sort, near the end, as follows:

<quote>
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.
</quote>

$LC_COLLATE is the part of the locale which says how to sort. if
$LC_ALL is set if overrides all the others, otherwise $LANG is used as
a fallback for any locale variable which is not set. ":lang" with no
arguments lists all settiings after taking care of $LANG and/or
$LC_ALL if present.

Best regards,
Tony.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAJkCKXs_EgN%2Bd9vm1VJUu%3D92%3DR0t6RGXW3sjQZqtucKMeu53cg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Chris Jones-44
On Tue, Oct 27, 2020 at 10:26:47PM EDT, Tony Mechelynck wrote:
> On Tue, Oct 27, 2020 at 11:55 PM Chris Jones <[hidden email]> wrote:

> A "stable" sort is a sort which will keep lines with the same sort
> keys in the order they were before the sort. (If you sort on whole
> lines the difference is not visible, unless there exist different
> lines which sort as equal, but if you sort on "pattern" or on "first
> number" it may matter.)
>
> But there is another few sentences which may be relevant in the help
> for :sort, near the end, as follows:
>
> <quote>
> 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.
> </quote>
>
> $LC_COLLATE is the part of the locale which says how to sort. if
> $LC_ALL is set if overrides all the others, otherwise $LANG is used as
> a fallback for any locale variable which is not set. ":lang" with no
> arguments lists all settiings after taking care of $LANG and/or
> $LC_ALL if present.

Thanks for reminding me what 'stable' means in this context. What I am
driving at is that... stable or not... I just need sort to do the job
right, which in this particular use case appears not to be the case.

In other words when I use the vim :sort command the output should have
index entries starting with É under letter E... Œ under letter O, etc.
which as far as I know is the way things work with French language
indexes.

As quoted above the ':help :sort' documentation proceeds to inform me
that I will have to 'try it out'. Seriously?

As it happens my original post explained just that. I 'tried it out' and
the result is either of two things: I did not 'try it out' right (user
error) or vim does not sort correctly (bug).

Now you're telling me that it's not vim's fault (couldn't care less
whose fault it is)... it's "the libary's".

So what's the next step?

Should I determine what library is at fault so I can discuss it with the
developer... or should I ask vim to kindly switch to a library that
actually works such as GNU's (coreutils) which as tested (cf. original
post) does sort correctly?

Thank you,

CJ

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201031191652.gnitlkzwur5z6nod%40turki.local.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Tekki-2
Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:

So what's the next step?


You could create your own sort command in vimrc, for example

command -nargs=1 Sort :.,+<args>!sort -

Then :Sort7 will sort the above list of letters corretly.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/2eedb209-e55f-4675-96b7-a581122055b7n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Dominique Pellé
Tekki <[hidden email]> wrote:

> Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:
>>
>>
>> So what's the next step?
>>
>
> You could create your own sort command in vimrc, for example
>
> command -nargs=1 Sort :.,+<args>!sort -
>
> Then :Sort7 will sort the above list of letters correctly.

Indeed, you could use %!sort to use the Unix sort command
instead of the Vim ex command  (possibly replace % with
another range if you don't want to sort the entire file).

That said, sorting using the locale ordering with Ex :sort
could be useful.   I see that ex_sort() in ex_cmds.c calls
sort_compare() and that function calls STRCMP() or
STRICMP().  strcmp() not use the locale, but strcoll() does.
We could consider adding a sorting option to honor the current
locale (e.g.  :sort l) which would compare using strcoll() instead
of STRCMP or STRICMP.

Regards
Dominique

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAON-T_gXRX71VO%2Bw%3DOEnkTVrMTLEoAss%2BuMw4EvrE1QEvRJCLQ%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Dominique Pellé
Dominique Pellé <[hidden email]> wrote:

> Tekki <[hidden email]> wrote:
>
> > Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:
> >>
> >>
> >> So what's the next step?
> >>
> >
> > You could create your own sort command in vimrc, for example
> >
> > command -nargs=1 Sort :.,+<args>!sort -
> >
> > Then :Sort7 will sort the above list of letters correctly.
>
> Indeed, you could use %!sort to use the Unix sort command
> instead of the Vim ex command  (possibly replace % with
> another range if you don't want to sort the entire file).
>
> That said, sorting using the locale ordering with Ex :sort
> could be useful.   I see that ex_sort() in ex_cmds.c calls
> sort_compare() and that function calls STRCMP() or
> STRICMP().  strcmp() not use the locale, but strcoll() does.
> We could consider adding a sorting option to honor the current
> locale (e.g.  :sort l) which would compare using strcoll() instead
> of STRCMP or STRICMP.

I just created a git pull request to implement sorting using the
current locale.  It adds a l option to the :sort Ex command.

See:

https://github.com/vim/vim/pull/7237

Regards
Dominique

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAON-T_iB%2BW_-4uOPGCu31gzRVtxaCwFQopmRDQQyu0PCKfkR-w%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Gary Johnson-4
On 2020-11-01, Dominique Pellé wrote:

> Dominique Pellé wrote:
>
> > Tekki wrote:
> >
> > > Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:
> > >>
> > >>
> > >> So what's the next step?
> > >>
> > >
> > > You could create your own sort command in vimrc, for example
> > >
> > > command -nargs=1 Sort :.,+<args>!sort -
> > >
> > > Then :Sort7 will sort the above list of letters correctly.
> >
> > Indeed, you could use %!sort to use the Unix sort command
> > instead of the Vim ex command  (possibly replace % with
> > another range if you don't want to sort the entire file).
> >
> > That said, sorting using the locale ordering with Ex :sort
> > could be useful.   I see that ex_sort() in ex_cmds.c calls
> > sort_compare() and that function calls STRCMP() or
> > STRICMP().  strcmp() not use the locale, but strcoll() does.
> > We could consider adding a sorting option to honor the current
> > locale (e.g.  :sort l) which would compare using strcoll() instead
> > of STRCMP or STRICMP.
>
> I just created a git pull request to implement sorting using the
> current locale.  It adds a l option to the :sort Ex command.
>
> See:
>
> https://github.com/vim/vim/pull/7237

Is this consistent with Christian's fix for #6229 in June?
I haven't looked at either patch closely--I just remembered that
this issue had been discussed before--but they seem to take
different approaches to setting the collation order.  I don't
particularly care how it's done, but I do care that it's done
consistently.

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201102013130.GA10555%40phoenix.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Dominique Pellé
Gary Johnson wrote:

> On 2020-11-01, Dominique Pellé wrote:
> > Dominique Pellé wrote:
> >
> > > Tekki wrote:
> > >
> > > > Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:
> > > >>
> > > >>
> > > >> So what's the next step?
> > > >>
> > > >
> > > > You could create your own sort command in vimrc, for example
> > > >
> > > > command -nargs=1 Sort :.,+<args>!sort -
> > > >
> > > > Then :Sort7 will sort the above list of letters correctly.
> > >
> > > Indeed, you could use %!sort to use the Unix sort command
> > > instead of the Vim ex command  (possibly replace % with
> > > another range if you don't want to sort the entire file).
> > >
> > > That said, sorting using the locale ordering with Ex :sort
> > > could be useful.   I see that ex_sort() in ex_cmds.c calls
> > > sort_compare() and that function calls STRCMP() or
> > > STRICMP().  strcmp() not use the locale, but strcoll() does.
> > > We could consider adding a sorting option to honor the current
> > > locale (e.g.  :sort l) which would compare using strcoll() instead
> > > of STRCMP or STRICMP.
> >
> > I just created a git pull request to implement sorting using the
> > current locale.  It adds a l option to the :sort Ex command.
> >
> > See:
> >
> > https://github.com/vim/vim/pull/7237
>
> Is this consistent with Christian's fix for #6229 in June?
> I haven't looked at either patch closely--I just remembered that
> this issue had been discussed before--but they seem to take
> different approaches to setting the collation order.  I don't
> particularly care how it's done, but I do care that it's done
> consistently.
>
> Regards,
> Gary

Hi Garry

I did not know or remember about Christian's patch
(vim-8.2.0988) which:
- introduced the read-only v:collate variable.
- and added an option using a dictionary parameter
  to use collation order with readdir() and readdirex(),.

Christian's patch did not affect :sort or sort().
My patch 8.2.1933 introduced options to :sort and sort()
to use collation order.

I don't think there are inconsistencies.  We could not
use a dictionary option to neither :sort and sort().
sort() already had a dict with different semantics.

That said, we could make minor clean-ups:
- the tests introduced by 8.2.1933 could check v:collate
  instead of checking execute("language collate").
- and the doc of :sort and :sort() could link to v:collate.

I wonder whether we really needed to introduce the
read-only v:collate given that the existing ":language collate"
was sufficient to check the collation order.

I also wonder whether there are other commands or
functions that could use collation order besides
readdir(), readdirex(), sort() and :sort.

Regards
Dominique

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CAON-T_jU7eF0HZUG%2Bt7osF9zzuRy8kW7vio1efFw7sw0OVre%3DA%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Christian Brabandt

On Mo, 02 Nov 2020, Dominique Pellé wrote:

> Gary Johnson wrote:
>
> > On 2020-11-01, Dominique Pellé wrote:
> > > Dominique Pellé wrote:
> > >
> > > > Tekki wrote:
> > > >
> > > > > Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:
> > > > >>
> > > > >>
> > > > >> So what's the next step?
> > > > >>
> > > > >
> > > > > You could create your own sort command in vimrc, for example
> > > > >
> > > > > command -nargs=1 Sort :.,+<args>!sort -
> > > > >
> > > > > Then :Sort7 will sort the above list of letters correctly.
> > > >
> > > > Indeed, you could use %!sort to use the Unix sort command
> > > > instead of the Vim ex command  (possibly replace % with
> > > > another range if you don't want to sort the entire file).
> > > >
> > > > That said, sorting using the locale ordering with Ex :sort
> > > > could be useful.   I see that ex_sort() in ex_cmds.c calls
> > > > sort_compare() and that function calls STRCMP() or
> > > > STRICMP().  strcmp() not use the locale, but strcoll() does.
> > > > We could consider adding a sorting option to honor the current
> > > > locale (e.g.  :sort l) which would compare using strcoll() instead
> > > > of STRCMP or STRICMP.
> > >
> > > I just created a git pull request to implement sorting using the
> > > current locale.  It adds a l option to the :sort Ex command.
> > >
> > > See:
> > >
> > > https://github.com/vim/vim/pull/7237
> >
> > Is this consistent with Christian's fix for #6229 in June?
> > I haven't looked at either patch closely--I just remembered that
> > this issue had been discussed before--but they seem to take
> > different approaches to setting the collation order.  I don't
> > particularly care how it's done, but I do care that it's done
> > consistently.
> >
> > Regards,
> > Gary
>
> Hi Garry
>
> I did not know or remember about Christian's patch
> (vim-8.2.0988) which:
> - introduced the read-only v:collate variable.
> - and added an option using a dictionary parameter
>   to use collation order with readdir() and readdirex(),.
>
> Christian's patch did not affect :sort or sort().
> My patch 8.2.1933 introduced options to :sort and sort()
> to use collation order.
>
> I don't think there are inconsistencies.  We could not
> use a dictionary option to neither :sort and sort().
> sort() already had a dict with different semantics.
>
> That said, we could make minor clean-ups:
> - the tests introduced by 8.2.1933 could check v:collate
>   instead of checking execute("language collate").
> - and the doc of :sort and :sort() could link to v:collate.
>
> I wonder whether we really needed to introduce the
> read-only v:collate given that the existing ":language collate"
> was sufficient to check the collation order.

I basically added the v:collate variable to be consistent with the other
v: variable, like v:lang and v:ctype and v:lc_time variable and I think
it is easier to get the current locale using those variables instead of
having to redir the :language [type] subcommand.

I remember that I intentionally left out the :sort and sort() functions,
because I wanted to fix the immediate problem first and left the rest
back then alone, wanting to do it later. It seems I forgot :( so thanks
for adding that.

> I also wonder whether there are other commands or
> functions that could use collation order besides
> readdir(), readdirex(), sort() and :sort.

Possible. I suppose if we need those, we can always enhance it further.

Best,
Christian
--
Stilblüten aus Schreiben von Versicherungsnehmern:
Ich bin von Beruf Schweißer.  Ihr Computer hat an der falschen Stelle
gespart und bei meinem Beruf das w weggelassen.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201102083320.GA32622%40256bit.org.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Chris Jones-44
In reply to this post by Tekki-2
On Sun, Nov 01, 2020 at 02:45:28AM EST, Tekki wrote:

> Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:
>
> >
> > So what's the next step?
> >
> >
> You could create your own sort command in vimrc, for example
>
> command -nargs=1 Sort :.,+<args>!sort -
>
> Then :Sort7 will sort the above list of letters corretly.
>
Gives the intended result. Thanks for spelling it out.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201105204026.6fidpzufnodxwd2p%40turki.local.
Reply | Threaded
Open this post in threaded view
|

Re: the :sort command does not appear to give expected result

Chris Jones-44
In reply to this post by Tekki-2
On Sun, Nov 01, 2020 at 02:45:28AM EST, Tekki wrote:
> Chris Jones schrieb am Samstag, 31. Oktober 2020 um 20:16:53 UTC+1:
>
> You could create your own sort command in vimrc, for example
>
> command -nargs=1 Sort :.,+<args>!sort -
>
> Then :Sort7 will sort the above list of letters corretly.

Now let's take this one step further.

What I am really trying to do is get rid of this file and do the
processing in-core using a vim dictionary.

In other words I have iterated over my source buffers and created a temp
file that contains key/value pairs that will serve as the basis for my
HTML index.

Now instead of this temp file that (as a reminder) contains something
like:

| Ï
| O
| E
| A
| É
| Æ
| I
| Œ

I create a vim dictionary that contains the same data:

| :let g:dict
| {'A': ' ', 'E': ' ', 'Æ': ' ', 'É': ' ', 'I': ' ', 'Œ': ' ', 'Ï': ' ', 'O': ' '}

I know I can loop over the contents of the dictionary like so:

| :for l in items(g:dict)
| :  let l
| :  endfor

handing me back the (unsorted) output:

| l                     ['A', ' ']
| l                     ['E', ' ']
| l                     ['Æ', ' ']
| l                     ['É', ' ']
| l                     ['I', ' ']
| l                     ['Œ', ' ']
| l                     ['Ï', ' ']
| l                     ['O', ' ']

Now I need this sorted alphabetically following French collating rules
... 'Æ' follows 'A'... 'É' follows 'E' etc.

So I have two problems:

1.  sort the output by key value (couldn't think of a simple way
    to do this off the bat¹...

2.  until the issue I described earlier in this thread is addressed
    I need to invoke gnu/coreutils' sort utility...

The solution to problem #1 should be pretty straightforward.

As to the second problem I need to pass my dictionary's entries to
gnu/sort in a way that somehow will return them sorted alphabetically.

Is this feasible using an external sort program?

Thanks,

CJ

¹ In python:

| for k, v in sorted(dict.items()):
|     print(k, v)

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201105222722.ilqlaltac2ekvj3e%40turki.local.