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: Sat, 06 Feb 2021 21:35:18 +0200 Organization: LINKOV.NET Message-ID: <87im75dm4t.fsf@mail.linkov.net> References: <87v9bb4tm2.fsf@mail.linkov.net> <83wnvr65zg.fsf@gnu.org> <875z3aooao.fsf@gnus.org> <87lfc666vr.fsf@mail.linkov.net> <87tuqti2kw.fsf@gnus.org> <87bld1hvwg.fsf@gnus.org> <87zh0lq6n8.fsf@mail.linkov.net> <87lfc4gtam.fsf@gnus.org> <87zh0kw4n1.fsf@mail.linkov.net> <87h7mrq002.fsf@gnus.org> <87pn1fo42e.fsf@mail.linkov.net> <831rdvq84d.fsf@gnu.org> 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="39417"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: larsi@gnus.org, 46240@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 06 20:39:10 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 1l8TQE-000A99-LQ for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Feb 2021 20:39:10 +0100 Original-Received: from localhost ([::1]:35960 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l8TQD-0002Yq-O3 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Feb 2021 14:39:09 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33232) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l8TQ6-0002Xz-0H for bug-gnu-emacs@gnu.org; Sat, 06 Feb 2021 14:39:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34918) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l8TQ5-00081B-Oc for bug-gnu-emacs@gnu.org; Sat, 06 Feb 2021 14:39:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l8TQ5-0005YR-LP for bug-gnu-emacs@gnu.org; Sat, 06 Feb 2021 14:39:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Feb 2021 19:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46240 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 46240-submit@debbugs.gnu.org id=B46240.161264032721327 (code B ref 46240); Sat, 06 Feb 2021 19:39:01 +0000 Original-Received: (at 46240) by debbugs.gnu.org; 6 Feb 2021 19:38:47 +0000 Original-Received: from localhost ([127.0.0.1]:46464 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8TPr-0005Xt-H0 for submit@debbugs.gnu.org; Sat, 06 Feb 2021 14:38:47 -0500 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:52935) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l8TPp-0005XQ-07 for 46240@debbugs.gnu.org; Sat, 06 Feb 2021 14:38:45 -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 relay7-d.mail.gandi.net (Postfix) with ESMTPSA id A1AB920005; Sat, 6 Feb 2021 19:38:36 +0000 (UTC) In-Reply-To: <831rdvq84d.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 05 Feb 2021 09:36:02 +0200") 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:199454 Archived-At: --=-=-= Content-Type: text/plain >> > Having the option to sort by names within each block sounds nice to me. >> >> Oh, then sorting order of sections would need own option. Currently >> sections are sorted by section names (i.e. mostly by script names >> alphabetically, e.g. "adlam", "aegean-number", "ahom", etc.), >> but a new option could sort them by their boundary codepoints >> (i.e. "basic-latin", "latin-supplement", "latin-extended"), >> so now options are going out of control :) > > I think we can get away with only one sorting order for sections: > alphabetically. Most tools I use that show large regions of Unicode > space do that, and I find it very convenient for quickly finding the > block I need without having to remember its place in the codepoint > order (which is quite random). Then customization will be much simpler with just 2 variables 'read-char-by-name-sort' and 'read-char-by-name-group': --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=read-char-by-name-group.patch diff --git a/etc/NEWS b/etc/NEWS index fb77688470..ed04bcdf13 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -851,6 +851,16 @@ iso-transl RET', it supports the same key sequences as 'C-x 8', so e.g. like 'C-x 8 [' inserts a left single quotation mark, 'C-x \ [' does the same. +--- +*** New user option 'read-char-by-name-sort'. +It can enable sorting the characters of completion from +'C-x 8 RET TAB' by codepoints instead of character names. + +--- +*** New user option 'read-char-by-name-group'. +It groups the characters of completion from 'C-x 8 RET TAB' +by Unicode blocks. + --- *** Improved language transliteration in Malayalam input methods. Added a new Mozhi scheme. The inapplicable ITRANS scheme is now diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 5dc3de4422..0df410987e 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3083,6 +3083,42 @@ mule--ucs-names-affixation (list name (concat (if char (format "%c" char) " ") "\t") ""))) names)) +(defun mule--ucs-names-group (names) + (let* ((codes-and-names + (mapcar (lambda (name) (cons (gethash name ucs-names) name)) names)) + (grouped + (seq-group-by + (lambda (code-name) + (let ((script (aref char-script-table (car code-name)))) + (if script (symbol-name script) "ungrouped"))) + codes-and-names)) + names-with-header header) + (dolist (group (sort grouped (lambda (a b) (string< (car a) (car b))))) + (setq header t) + (dolist (code-name (cdr group)) + (push (list + (cdr code-name) + (concat + (if header + (progn + (setq header nil) + (concat "\n" (propertize + (format "* %s\n" (car group)) + 'face 'header-line))) + "") + ;; prefix + (if (car code-name) (format "%c" (car code-name)) " ") "\t") + ;; suffix + "") + names-with-header))) + (nreverse names-with-header))) + +(defun mule--ucs-names-sort-by-code (names) + (let* ((codes-and-names + (mapcar (lambda (name) (cons (gethash name ucs-names) name)) names)) + (sorted (sort codes-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. @@ -3104,6 +3140,22 @@ char-from-name ignore-case)) code))))))) +(defcustom read-char-by-name-sort nil + "How to sort characters for `read-char-by-name' completion." + :type '(choice + (const :tag "Sort by character names" nil) + (const :tag "Sort by character codepoints" code)) + :group 'mule + :version "28.1") + +(defcustom read-char-by-name-group nil + "How to group characters for `read-char-by-name' completion. +When non-nil, split characters to sections of Unicode blocks +sorted alphabetically." + :type 'boolean + :group 'mule + :version "28.1") + (defun read-char-by-name (prompt) "Read a character by its Unicode name or hex number string. Display PROMPT and read a string that represents a character by its @@ -3130,8 +3182,14 @@ read-char-by-name prompt (lambda (string pred action) (if (eq action 'metadata) - '(metadata - (affixation-function . mule--ucs-names-affixation) + `(metadata + (affixation-function + . ,(if read-char-by-name-group + 'mule--ucs-names-group + 'mule--ucs-names-affixation)) + (display-sort-function + . ,(when (eq read-char-by-name-sort 'code) + 'mule--ucs-names-sort-by-code)) (category . unicode-name)) (complete-with-action action (ucs-names) string pred))))) (char --=-=-=--