unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#46240: Sorting order of read-char-by-name
@ 2021-02-01 17:23 Juri Linkov
  2021-02-01 17:41 ` Eli Zaretskii
  2021-02-01 19:35 ` bug#46240: [External] : " Drew Adams
  0 siblings, 2 replies; 33+ messages in thread
From: Juri Linkov @ 2021-02-01 17:23 UTC (permalink / raw)
  To: 46240

[-- Attachment #1: Type: text/plain, Size: 1293 bytes --]

Tags: patch

After typing e.g. 'C-x 8 RET GREEK TAB' completions are sorted in an
non-alphabetical order:

Ͳ	GREEK CAPITAL LETTER ARCHAIC SAMPI
Β	GREEK CAPITAL LETTER BETA
Χ	GREEK CAPITAL LETTER CHI
Ϯ	GREEK CAPITAL LETTER DEI
Δ	GREEK CAPITAL LETTER DELTA

where the 22nd letter of the Greek alphabet CHI is between BETA and DELTA.
This is because currently completions are sorted by English names.

The following patch sorts them by their Unicode order that mostly follows
the alphabetical order, and at least makes more sense to be consistent
with Unicode tables where characters are grouped more logically.
Then the above example is sorted alphabetically:

Α	GREEK CAPITAL LETTER ALPHA
Β	GREEK CAPITAL LETTER BETA
Γ	GREEK CAPITAL LETTER GAMMA
Δ	GREEK CAPITAL LETTER DELTA
Ε	GREEK CAPITAL LETTER EPSILON

More examples with better sorting is 'C-x 8 RET SUBSCRIPT TAB'
where instead of sorting by names of numbers:

₈	SUBSCRIPT DIGIT EIGHT
₅	SUBSCRIPT DIGIT FIVE
₄	SUBSCRIPT DIGIT FOUR
₉	SUBSCRIPT DIGIT NINE
₁	SUBSCRIPT DIGIT ONE
₇	SUBSCRIPT DIGIT SEVEN
₆	SUBSCRIPT DIGIT SIX

will be sorted by numerical order:

₀	SUBSCRIPT DIGIT ZERO
₁	SUBSCRIPT DIGIT ONE
₂	SUBSCRIPT DIGIT TWO
₃	SUBSCRIPT DIGIT THREE
₄	SUBSCRIPT DIGIT FOUR
₅	SUBSCRIPT DIGIT FIVE

etc.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mule--ucs-names-sort-by-char.patch --]
[-- Type: text/x-diff, Size: 1096 bytes --]

diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index 5dc3de4422..0593d72279 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -3083,6 +3083,12 @@ mule--ucs-names-affixation
               (list name (concat (if char (format "%c" char) " ") "\t") "")))
           names))
 
+(defun mule--ucs-names-sort-by-char (names)
+  (let* ((chars-and-names
+          (mapcar (lambda (name) (cons (gethash name ucs-names) name)) names))
+         (sorted (sort chars-and-names (lambda (a b) (< (car a) (car b))))))
+    (mapcar #'cdr sorted)))
+
 (defun char-from-name (string &optional ignore-case)
   "Return a character as a number from its Unicode name STRING.
 If optional IGNORE-CASE is non-nil, ignore case in STRING.
@@ -3132,6 +3138,7 @@ read-char-by-name
 	     (if (eq action 'metadata)
 		 '(metadata
 		   (affixation-function . mule--ucs-names-affixation)
+		   (display-sort-function . mule--ucs-names-sort-by-char)
 		   (category . unicode-name))
 	       (complete-with-action action (ucs-names) string pred)))))
 	 (char

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

end of thread, other threads:[~2021-02-09 19:16 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-01 17:23 bug#46240: Sorting order of read-char-by-name Juri Linkov
2021-02-01 17:41 ` Eli Zaretskii
2021-02-02  8:40   ` Lars Ingebrigtsen
2021-02-02 17:16     ` Juri Linkov
2021-02-02 17:57       ` bug#46240: [External] : " Drew Adams
2021-02-02 18:47       ` Eli Zaretskii
2021-02-03 15:38       ` Lars Ingebrigtsen
2021-02-03 18:02         ` Lars Ingebrigtsen
2021-02-03 18:17           ` Eli Zaretskii
2021-02-03 18:21             ` Lars Ingebrigtsen
2021-02-03 18:40               ` Eli Zaretskii
2021-02-03 19:43           ` Juri Linkov
2021-02-04  7:56             ` Lars Ingebrigtsen
2021-02-04  9:32               ` Juri Linkov
2021-02-04 16:19                 ` Lars Ingebrigtsen
2021-02-04 22:34                   ` Juri Linkov
2021-02-05  7:36                     ` Eli Zaretskii
2021-02-06 19:35                       ` Juri Linkov
2021-02-06 20:01                         ` Eli Zaretskii
2021-02-07 18:56                           ` Juri Linkov
2021-02-07 19:54                             ` Eli Zaretskii
2021-02-09 18:13                               ` Juri Linkov
2021-02-09 19:00                                 ` Eli Zaretskii
2021-02-09 19:16                                   ` Juri Linkov
2021-02-02 17:13   ` Juri Linkov
2021-02-02 18:44     ` Eli Zaretskii
2021-02-03 17:27       ` Juri Linkov
2021-02-03 17:54         ` Eli Zaretskii
2021-02-03 19:44           ` Juri Linkov
2021-02-03 15:35     ` Lars Ingebrigtsen
2021-02-01 19:35 ` bug#46240: [External] : " Drew Adams
2021-02-02 17:18   ` Juri Linkov
2021-02-02 17:49     ` Drew Adams

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