On Mon, Jan 6, 2025 at 9:49 PM Michael Brand <michael.ch.br...@gmail.com> wrote: > My patch _neutralizes_ the ignore case behavior of ~string-collate-lessp~.
The attached patches implement this suggestion and are applicable on bugfix and main. Tested with Emacs 29.4 of Homebrew on macOS. Please review and if someone can test the final version also on Linux and Windows I suggest to apply on bugfix.
From c14d387343e4cb20fe3018fbe991797d20a9f29f Mon Sep 17 00:00:00 2001 From: Michael Brand <michael.ch.brand@gmail.com> Date: Wed, 8 Jan 2025 17:47:14 +0100 Subject: [PATCH 1/2] Align test with other tests * testing/lisp/test-org-table.el (test-org-table/sort-lines): `(org-table-sort-lines nil ?A)' is already tested, change it to the missing `(org-table-sort-lines t ?A)'. --- testing/lisp/test-org-table.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index df63a65fc..cfc8e2a0b 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1908,6 +1908,7 @@ See also `test-org-table/copy-field'." (lambda (s1 s2 &optional _locale ignore-case) (funcall original-string-collate-lessp s1 s2 "C" ignore-case)))) + ;; Sort alphabetically ignore case. (should (equal "| a | x |\n| B | 4 |\n| c | 3 |\n" (org-test-with-temp-text "| <point>a | x |\n| c | 3 |\n| B | 4 |\n" @@ -1925,9 +1926,9 @@ See also `test-org-table/copy-field'." (org-table-sort-lines t ?a) (buffer-string)))) (should - (equal "| C |\n| b |\n| a |\n" + (equal "| b |\n| a |\n| C |\n" (org-test-with-temp-text "| <point>a |\n| C |\n| b |\n" - (org-table-sort-lines nil ?A) + (org-table-sort-lines t ?A) (buffer-string)))))) ;; Sort by time (timestamps) (should -- 2.39.3 (Apple Git-145)
From 9aeafc6bc9209f56ce757f1ae9b600f804ec3ad7 Mon Sep 17 00:00:00 2001 From: Michael Brand <michael.ch.brand@gmail.com> Date: Wed, 8 Jan 2025 17:47:17 +0100 Subject: [PATCH 2/2] Fix test for when ignore case is not supported * testing/lisp/test-org-table.el (test-org-table/sort-lines): Fix test for when `string-collate-lessp' does not support ignore case. * testing/org-test.el (;;; Functions for writing tests): Add function `org-test-string-collate-lessp-ignore-case-supported-p'. In the context of the `cl-letf' of `test-org-table/sort-lines' the new `org-test-string-collate-lessp-ignore-case-supported-p' evaluates to nil with Emacs 29.4 of Homebrew on macOS. --- testing/lisp/test-org-table.el | 8 ++++++-- testing/org-test.el | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/testing/lisp/test-org-table.el b/testing/lisp/test-org-table.el index cfc8e2a0b..3e75d506e 100644 --- a/testing/lisp/test-org-table.el +++ b/testing/lisp/test-org-table.el @@ -1910,12 +1910,16 @@ See also `test-org-table/copy-field'." s1 s2 "C" ignore-case)))) ;; Sort alphabetically ignore case. (should - (equal "| a | x |\n| B | 4 |\n| c | 3 |\n" + (equal (if (org-test-string-collate-lessp-ignore-case-supported-p) + "| a | x |\n| B | 4 |\n| c | 3 |\n" + "| B | 4 |\n| a | x |\n| c | 3 |\n") (org-test-with-temp-text "| <point>a | x |\n| c | 3 |\n| B | 4 |\n" (org-table-sort-lines nil ?a) (buffer-string)))) (should - (equal "| c | 3 |\n| B | 4 |\n| a | x |\n" + (equal (if (org-test-string-collate-lessp-ignore-case-supported-p) + "| c | 3 |\n| B | 4 |\n| a | x |\n" + "| c | 3 |\n| a | x |\n| B | 4 |\n") (org-test-with-temp-text "| <point>a | x |\n| c | 3 |\n| B | 4 |\n" (org-table-sort-lines nil ?A) (buffer-string)))) diff --git a/testing/org-test.el b/testing/org-test.el index 643c5c766..99d5f7c4a 100644 --- a/testing/org-test.el +++ b/testing/org-test.el @@ -309,6 +309,19 @@ Tramp related features. We mostly follow (declare (debug (sexp body)) (indent 2)) `(org-test-with-tramp-remote-dir--worker (lambda (,dir) ,@body))) +(defun org-test-string-collate-lessp-ignore-case-supported-p + (&optional locale) + "`string-collate-lessp' supports ignore case for LOCALE. +According to the docstring of `string-collate-lessp' it does not +implement ignore case for some locale on some operating systems, +actually depending on libc of Emacs. `string-collate-lessp' +ignores when its parameter IGNORE-CASE is non-nil e. g. for the C +locale in Emacs 29.4 of Homebrew on macOS. + +See also https://debbugs.gnu.org/cgi/bugreport.cgi?bug=59275 and +https://list.orgmode.org/orgmode/m2ilkwso8r.fsf@me.com" + (let ((ignore-case t)) + (string-collate-lessp "a" "B" locale ignore-case))) ;;; Navigation Functions -- 2.39.3 (Apple Git-145)