emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix alphabetic sorting for headlines, tags
@ 2018-02-06 10:07 Sebastian Reuße
  2018-02-10 13:02 ` Nicolas Goaziou
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastian Reuße @ 2018-02-06 10:07 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Sebastian Reuße

* 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-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.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 688e48bcc..dc0611b87 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" 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) '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))))
 
+(defun org-string-collate-greaterp (s1 s2 &optional locale ignore-case)
+  "Return t if S1 is greater than S2 in collation order.
+
+LOCALE and IGNORE-CASE are handled as in `string-collate-lessp'."
+  (not (string-collate-lessp s1 s2 locale ignore-case)))
+
 ;;;###autoload
 (defun org-run-like-in-org-mode (cmd)
   "Run a command, pretending that the current buffer is in Org mode.
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH] Fix alphabetic sorting for headlines, tags
@ 2018-02-06  8:57 Sebastian Reuße
  0 siblings, 0 replies; 12+ messages in thread
From: Sebastian Reuße @ 2018-02-06  8:57 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Sebastian Reuße

* 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-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.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 688e48bcc..d54c410b0 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" 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) '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))))
 
+(defun org-string-collate-greaterp (s1 s2 &optional locale ignore-case)
+  "Return t if S1 is greater than S2 in collation order.
+
+LOCALE and IGNORE-CASE are handled as in `string-collate-lessp'."
+  (not (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.
-- 
2.16.1

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-02-12 15:47 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-06 10:07 [PATCH] Fix alphabetic sorting for headlines, tags Sebastian Reuße
2018-02-10 13:02 ` Nicolas Goaziou
2018-02-11 11:11   ` Sebastian Reuße
2018-02-11 16:25     ` Nicolas Goaziou
2018-02-12  8:44       ` Sebastian Reuße
2018-02-12 14:03         ` Nicolas Goaziou
2018-02-12 14:54           ` Sebastian Reuße
2018-02-12 15:47             ` Nicolas Goaziou
2018-02-12  8:46       ` Sebastian Reuße
2018-02-12 13:59         ` Nicolas Goaziou
2018-02-11 11:13   ` Sebastian Reuße
  -- strict thread matches above, loose matches on Subject: below --
2018-02-06  8:57 Sebastian Reuße

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).