unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: 59275@debbugs.gnu.org
Subject: bug#59275: Unexpected return value of `string-collate-lessp' on Mac
Date: Wed, 16 Nov 2022 15:00:06 +0200	[thread overview]
Message-ID: <83mt8rgill.fsf@gnu.org> (raw)
In-Reply-To: <8735ajel7y.fsf@localhost> (message from Ihor Radchenko on Wed, 16 Nov 2022 01:34:09 +0000)

> From: Ihor Radchenko <yantar92@posteo.net>
> Cc: 59275@debbugs.gnu.org
> Date: Wed, 16 Nov 2022 01:34:09 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> >> > string-collate-lessp is inherently platform- (and locale-) dependent.
> >> > Don't use it if you want consistent results across platforms and
> >> > locales.
> >> 
> >> Is there a better alternative?
> >
> > Alternative to do what job?
> 
> Reliable sorting.
> In particular, I am looking for a better PREDICATE argument for
> `sort-subr' for case-sensitive and case-insensitive sorting of strings.

In the strict order of Unicode codepoints?  Use compare-strings.

> >> Also, do I miss something, or is this pitfall not documented in the
> >> docstring of `string-collate-lessp'?
> >
> > It isn't? then what is this about:
> >
> >   This function obeys the conventions for collation order in your
> >   locale settings.  For example, punctuation and whitespace characters
> >   might be considered less significant for sorting:
> >
> >   (sort '("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp)
> >     => ("11" "1 1" "1.1" "12" "1 2" "1.2")
> >   [...]
> >   To emulate Unicode-compliant collation on MS-Windows systems,
> >   bind ‘w32-collate-ignore-punctuation’ to a non-nil value, since
> >   the codeset part of the locale cannot be "UTF-8" on MS-Windows.
> 
> The above sounds like we just need to worry about some edge cases where
> different approaches may exist to sorting. Like with punctuation,
> numbers, and spaces.
> 
> Having
> 
>   (string-collate-lessp "a" "B" "C" t)  ; => nil
> 
> is totally unexpected because case-insensitive "a"<"B"<"C" sounds like
> the only reasonable outcome.

It is hard to guess what will be unexpected for people.  When the doc
string was written, the example used there was deemed to be the most
striking surprise from using locale-dependent collation, so it was
what we used.

> I'd like the warning to be even more prominent.

You want to make it explicit that for systems where we use
string-lessp the IGNORE-CASE argument is ignored?  Or do you want some
other change?

Anyway, feel free to suggest some text to that effect.





  reply	other threads:[~2022-11-16 13:00 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15  4:08 bug#59275: Unexpected return value of `string-collate-lessp' on Mac Ihor Radchenko
2022-11-15  9:51 ` Robert Pluim
2022-11-16  3:47   ` Ihor Radchenko
2022-11-15 13:46 ` Eli Zaretskii
2022-11-15 15:05   ` Ihor Radchenko
2022-11-15 15:16     ` Eli Zaretskii
2022-11-16  1:34       ` Ihor Radchenko
2022-11-16 13:00         ` Eli Zaretskii [this message]
2022-11-21  7:28           ` Ihor Radchenko
2022-11-21 13:31             ` Eli Zaretskii
2022-11-22  1:24               ` Ihor Radchenko
2022-11-22 12:56                 ` Eli Zaretskii
2022-11-23 10:39                   ` Ihor Radchenko
2022-11-23 14:58                     ` Eli Zaretskii
2022-11-24  2:22                       ` Ihor Radchenko
2022-11-24  7:23                         ` Eli Zaretskii
2022-11-26  2:03                   ` Ihor Radchenko
2022-11-26  8:06                     ` Eli Zaretskii
2022-11-26  8:47                       ` Ihor Radchenko
2022-11-26  9:22                         ` Eli Zaretskii
2022-11-27 14:00                           ` Maxim Nikulin
2022-11-27 14:23                             ` Eli Zaretskii
2022-11-27 15:19                               ` Maxim Nikulin
2022-11-27 15:42                                 ` Eli Zaretskii

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=83mt8rgill.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=59275@debbugs.gnu.org \
    --cc=yantar92@posteo.net \
    /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.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).