emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Max Nikulin <manikulin@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: test-org-table/sort-lines: Failing test on macOS
Date: Wed, 23 Nov 2022 10:37:08 +0000	[thread overview]
Message-ID: <87k03mhs8b.fsf@localhost> (raw)
In-Reply-To: <tliroo$6vd$1@ciao.gmane.io>

Max Nikulin <manikulin@gmail.com> writes:

> On 22/11/2022 08:14, Ihor Radchenko wrote:
>> Max Nikulin writes:
>> 
>>>> 2. `org-sort-list'
>>>> 5. `org-sort-entries'
>>> `downcase' is used, not proper case folding, so a potential issue
>> 
>> `downcase' is used to determine user input about sorting type.
>> Not for sorting itself.
>
> See case-func variable. Its initialization depends on the IGNORE-CASE 
> argument. Strings to sort are passed either through `identity' or 
> through `downcase'.

Thanks for the pointer.
Now, I am getting more confused though.
Do we even need to use `string-collate-lessp' then?

Eli even argued that `string-collate-lessp' is strictly worse compared
to more predictable approach. See
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59275#40

Do you remember any cases when users actually demanded locale-specific
sorting?

>>> IGNORE-CASE argument is not used, perhaps `downcase' is hidden in the code.
>> 
>> I feel like we are slightly miscommunicating here.
>> I mostly tried to list the uses of libc-sensitive sorting. Not
>> specifically cases when we try to ignore the case.
>> 
>> The problem is not limited to case-sensitive comparisons. Some systems
>> may fail to implement specific locales and thus sorting may downgrade to
>> simple string-lessp.
>
> When case folding is not involved, I consider `string-lessp' as a 
> graceful degradation. Despite locale rules are not applied, strings are 
> mostly sorted. Exceptions exist, but usually order is reasonable.
>
> Completely disregarding IGNORE-CASE argument of `string-collate-lessp' 
> on MacOS (that is not a heavily stripped embedded OS) is a bad surprise 
> for me.

It was a surprise for me as well. Should be at least a bit more clear
now as I updated the docstring of `string-collate-lessp'.

However, I feel a bit lost about what to do on Org side.
We can put a disclaimer in the manual and all that, but it still feels
too complex.

>>>> 6. Agenda sorting, when alphabetical sorting is involved
>>>
>>> `string-lessp' and `downcase' so even more severe locale-related issues
>>> might be expected.
>> 
>> Could you please elaborate?
>
> I admit that `downcase' may be an acceptable workaround since 
> `string-collate-lessp' may not work IGNORE-CASE, but I believe, when 
> available, `string-collate-lessp' should be the preferred option for 
> sorting.

As I pointed above, Eli has an opposite opinion.
I feel that my understanding of the topic is not sufficient to judge.
Maybe we should ask users? (But who is even aware about these things
happening under the hood?)

> I have an idea of a compatibility wrapper for `string-collate-lessp' 
> with special treatment of ignoring case and bad libc implementation. 
> Apply `downcase' before passing arguments to `string-lessp'. It should 
> provide consistency, best user experience when locales works properly, 
> and graceful degradation otherwise. I hope, it is acceptable for Org 
> even though such trick is undesired for Emacs due to performance reasons.

Macro idea sounds reasonable. Though I am still unsure which direction
we need to go.

> However I am afraid of compatibility shims after
>
> d3a9c424b 2022-08-16 17:15:27 +0800 Ihor Radchenko: org-encode-time: 
> Refactor into top-level `defmacro'

What do you refer to?

> I do not like that Emacs relies on locale support (and timezone as well) 
> in libc. It becomes a problem as soon as more than one locale should be 
> used in simultaneously. I agree that there are enough complications and 
> sometimes locale depends on the document (e.g. #+LANGUAGE:), sometimes 
> specific locale even restricted to a part of a document. It is tricky to 
> handle such cases, but current limitations are too strict (and defective 
> `string-collate-lessp' on MacOS is an example).

The question is what can be done and, more importantly, how much effort
will it take to implement and maintain an alternative.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


  reply	other threads:[~2022-11-23 10:38 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-06 20:15 test-org-table/sort-lines: Failing test on macOS Rudolf Adamkovič
2022-10-07 12:04 ` Max Nikulin
2022-10-08  5:25   ` Ihor Radchenko
2022-10-08 14:27     ` Max Nikulin
2022-10-09  3:59       ` Ihor Radchenko
2022-10-09 15:38         ` Rudolf Adamkovič
2022-10-09 16:53           ` Max Nikulin
2022-10-10 22:25             ` Rudolf Adamkovič
2022-10-12 16:09               ` Max Nikulin
2022-11-15  4:10                 ` Ihor Radchenko
2022-11-20  4:18                   ` Ihor Radchenko
2022-11-20  8:00                     ` Max Nikulin
2022-11-21  3:15                       ` Ihor Radchenko
2022-11-21 16:48                         ` Max Nikulin
2022-11-22  1:14                           ` Ihor Radchenko
2022-11-22 16:01                             ` Max Nikulin
2022-11-23 10:37                               ` Ihor Radchenko [this message]
2022-11-23 15:27                                 ` Max Nikulin
2022-11-23 17:01                                   ` Max Nikulin
2022-11-26  2:05                                   ` Ihor Radchenko
2022-11-29 16:40                                     ` Max Nikulin
2024-04-03 11:40                                       ` [DISCUSSION] Sorting strings in Org mode vs. system locale (was: test-org-table/sort-lines: Failing test on macOS) Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k03mhs8b.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=manikulin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).