* org.el (org-sort-entries): Use collated sorting. (org-tags-sort-function): Use collated sorting. (org-string-collate-greaterp): Add helper-function to use as defcustom option, since there is no ‘string-collate-greaterp’ in Emacs.
* org-compat.el (org-string-collate-lessp): Add proxy to fall-back on string-lessp when string-collate-lessp is missing (Emacs ≤ 24). * test-org.el (test-org/string-collate-lessp): Add test. ‘org-sort-entries’ and ‘org-tags-sort-function’ advertise alphabetic sorting, but actually sort based only on character code. This produces non-alphabetic orderings of strings in non-ASCII locales. E. g., German Umlauts “Ä Ü Ö” are alphabetically sorted as if they were “A U O”, whereas sorting based on character-code will place them after “Z”, which is unexpected. --- lisp/org-compat.el | 6 ++++++ lisp/org.el | 12 +++++++++--- testing/lisp/test-org.el | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index 2553286e1..acd5c3e1e 100644 --- a/lisp/org-compat.el +++ b/lisp/org-compat.el @@ -118,6 +118,12 @@ (defvar org-table1-hline-regexp) (push (expand-file-name file dir) files))))) (nconc result (nreverse files))))) +;; `string-collate-lessp' is new in Emacs 25. +(defalias 'org-string-collate-lessp + (if (fboundp 'string-collate-lessp) + 'string-collate-lessp + 'string-lessp)) + ;;; Obsolete aliases (remove them after the next major release). diff --git a/lisp/org.el b/lisp/org.el index 688e48bcc..fbbeea80f 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -3558,8 +3558,8 @@ (defcustom org-tags-sort-function nil :group 'org-tags :type '(choice (const :tag "No sorting" nil) - (const :tag "Alphabetical" string<) - (const :tag "Reverse alphabetical" string>) + (const :tag "Alphabetical" org-string-collate-lessp) + (const :tag "Reverse alphabetical" org-string-collate-greaterp) (function :tag "Custom function" nil))) (defvar org-tags-history nil @@ -8803,7 +8803,7 @@ (defun org-sort-entries (t (error "Invalid sorting type `%c'" sorting-type)))) nil (cond - ((= dcst ?a) 'string<) + ((= dcst ?a) 'org-string-collate-lessp) ((= dcst ?f) (or compare-func (and interactive? @@ -8913,6 +8913,12 @@ (defun org-context-p (&rest contexts) (org-in-item-p))) (goto-char pos)))) +;; Defined to provide a value for defcustom, since there is no +;; string-collate-greaterp in Emacs. +(defun org-string-collate-greaterp (s1 s2) + "Return non-nil if S1 is greater than S2 in collation order." + (not (org-string-collate-lessp s1 s2))) + ;;;###autoload (defun org-run-like-in-org-mode (cmd) "Run a command, pretending that the current buffer is in Org mode. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index cb21cda47..ec4535551 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -2927,6 +2927,11 @@ (org-sort-entries nil ?a) (buffer-string))))) +(ert-deftest test-org/string-collate-greaterp () + "Test `org-string-collate-greaterp' specifications." + (should (org-string-collate-greaterp "def" "abc")) + (should-not (org-string-collate-greaterp "abc" "def"))) + (ert-deftest test-org/file-contents () "Test `org-file-contents' specifications." ;; Open files. -- 2.16.1