From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#46240: Sorting order of read-char-by-name Date: Mon, 01 Feb 2021 19:23:41 +0200 Organization: LINKOV.NET Message-ID: <87v9bb4tm2.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12481"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) To: 46240@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 01 18:25:45 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l6cxM-00036s-9q for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Feb 2021 18:25:44 +0100 Original-Received: from localhost ([::1]:53872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l6cxL-0000sV-87 for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 01 Feb 2021 12:25:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:37194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6cwg-0000r8-Ke for bug-gnu-emacs@gnu.org; Mon, 01 Feb 2021 12:25:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l6cwg-0003FD-Aa for bug-gnu-emacs@gnu.org; Mon, 01 Feb 2021 12:25:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l6cwg-0003vW-4p for bug-gnu-emacs@gnu.org; Mon, 01 Feb 2021 12:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 01 Feb 2021 17:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 46240 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.161220025915034 (code B ref -1); Mon, 01 Feb 2021 17:25:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 1 Feb 2021 17:24:19 +0000 Original-Received: from localhost ([127.0.0.1]:33054 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l6cvy-0003uN-Aw for submit@debbugs.gnu.org; Mon, 01 Feb 2021 12:24:19 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:47280) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l6cvw-0003u9-8n for submit@debbugs.gnu.org; Mon, 01 Feb 2021 12:24:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6cvw-0000R4-2e for bug-gnu-emacs@gnu.org; Mon, 01 Feb 2021 12:24:16 -0500 Original-Received: from relay2-d.mail.gandi.net ([217.70.183.194]:46973) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l6cvs-0002iy-Cc for bug-gnu-emacs@gnu.org; Mon, 01 Feb 2021 12:24:15 -0500 X-Originating-IP: 91.129.108.204 Original-Received: from mail.gandi.net (m91-129-108-204.cust.tele2.ee [91.129.108.204]) (Authenticated sender: juri@linkov.net) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id D0B5F40012; Mon, 1 Feb 2021 17:24:07 +0000 (UTC) Received-SPF: pass client-ip=217.70.183.194; envelope-from=juri@linkov.net; helo=relay2-d.mail.gandi.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:199094 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=mule--ucs-names-sort-by-char.patch 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 --=-=-=--