Thursday, November 5, 2020

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

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 vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20201105222722.ilqlaltac2ekvj3e%40turki.local.

No comments:

Post a Comment