On 05/05/2024 18:59, Ihor Radchenko wrote:
Ihor Radchenko writes:

If a user access same files from Linux and macOS then it
may be really annoying to get different order of entries in agenda. For
most of Linux users it is better to use more smart
`string-collate-lessp'. Some care is required to sort entries obtained
from multiple buffers in predictable environment (locale, case
conversion table).

I agree. We can introduce a new customization -
`org-string-sort-function' that will be used across Org mode to sort
user text.

See the attached tentative patch.
I added a customization, made everything in Org obey it, and provided
some default options for MacOS users.

Contrary to Eli, I still think that there are enough locales where completely disregarding IGNORE-CASE is worse than fallback to `downcase' when IGNORE-CASE is t. Perhaps some kind of normalization (NFD?) may improve results further.

I consider the following as a kind of graceful degradation

(defun org-sort-function-fallback-downcase
   (a b &optional LOCALE IGNORE-CASE)
 (if ignore-case
    (string-collate-lessp (downcase a) (downcase b) locale ignore-case)
  (string-collate-lessp a b locale ignore-case)))

(defcustom org-sort-function
 (if (string-collate-lessp "a" "B" "C" t)
    #'string-collate-lessp
  #'org-sort-function-fallback-downcase))

I would consider a setter function for `org-sort-function' to avoid branches based of `func-arity' in `org-string<'.

I see a little point in purely downcase comparator `org-sort-function-downcase'.


Reply via email to