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: Thu, 04 Feb 2021 11:32:27 +0200 Organization: LINKOV.NET Message-ID: <87zh0kw4n1.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> 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="473"; 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: 46240@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Feb 04 10:51:35 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 1l7bIU-000AYQ-CB for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Feb 2021 10:51:34 +0100 Original-Received: from localhost ([::1]:57704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l7bIT-00068L-Bh for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 04 Feb 2021 04:51:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l7bG2-0004V3-Pc for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 04:49:06 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l7bG2-0003iz-HL for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 04:49:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l7bG2-0005RD-Fo for bug-gnu-emacs@gnu.org; Thu, 04 Feb 2021 04:49: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: Thu, 04 Feb 2021 09:49:02 +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.161243212720880 (code B ref 46240); Thu, 04 Feb 2021 09:49:02 +0000 Original-Received: (at 46240) by debbugs.gnu.org; 4 Feb 2021 09:48:47 +0000 Original-Received: from localhost ([127.0.0.1]:39743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7bFj-0005Qe-FL for submit@debbugs.gnu.org; Thu, 04 Feb 2021 04:48:47 -0500 Original-Received: from relay7-d.mail.gandi.net ([217.70.183.200]:37067) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l7bFh-0005QO-AJ for 46240@debbugs.gnu.org; Thu, 04 Feb 2021 04:48:42 -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 ECDF820004; Thu, 4 Feb 2021 09:48:33 +0000 (UTC) In-Reply-To: <87lfc4gtam.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 04 Feb 2021 08:56:33 +0100") 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:199282 Archived-At: --=-=-= Content-Type: text/plain >> I've implemented this in >> https://lists.gnu.org/archive/html/emacs-devel/2020-11/msg00884.html >> but the implementation was not too compact, >> so I'm not sure if it's worth adding as an option. > > Looks nice! Adding it as an option sounds like a good idea to me... > but would this need another variable in addition to the other variable > you proposed to just alter the sorting, or could these things somehow be > the same variable? Better to try adding all options to the same variable to reduce the number of knobs. > Adding these headers would only make sense if the user is sorting by > code instead of name... so could the `read-char-by-name-sort-function' > variable instead be, say, `read-char-by-name-display' with values > `names', `code', `sections' (where `names' would be the current one, > `code' just sort by code, and `sections' would sort by code, and display > headings)? Or something along those lines? Yep. The only difference that this patch (that contains previous implementation of grouping by blocks) uses `nil' instead of `names' since this is the default value. Oops, I noticed that my previous implementation sorted by names inside each block, not by code. I'm not sure if this makes sense? Definitely, sorting by code inside blocks should be implemented as the primary feature, but should an additional option with previous implementation be retained to sort inside blocks by names too? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=read-char-by-name-display.patch diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index 5dc3de4422..465fd1bf53 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el @@ -3083,6 +3083,43 @@ mule--ucs-names-affixation (list name (concat (if char (format "%c" char) " ") "\t") ""))) names)) +(defun mule--ucs-names-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 mule--ucs-names-by-group (names) + (let* ((names-chars + (mapcar (lambda (name) (cons name (gethash name ucs-names))) names)) + (groups-names + (seq-group-by + (lambda (name-char) + (let ((script (aref char-script-table (cdr name-char)))) + (if script (symbol-name script) "ungrouped"))) + names-chars)) + names-headers header) + (dolist (group groups-names) + (setq header t) + (dolist (name-char (cdr group)) + (push (list (car name-char) + (concat + ;; header + (if header + (progn + (setq header nil) + (concat "\n" (propertize + (format "* %s\n" (car group)) + 'face 'header-line))) + "") + ;; prefix + (if (cdr name-char) (format "%c" (cdr name-char)) " ") + " ") + ;; suffix + "") + names-headers))) + (nreverse names-headers))) + (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 +3141,15 @@ char-from-name ignore-case)) code))))))) +(defcustom read-char-by-name-display nil + "How to display characters by `read-char-by-name' completion." + :type '(choice + (const :tag "Sort by character names" nil) + (const :tag "Sort by character codepoints" code) + (const :tag "Group by Unicode blocks" sections)) + :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 +3176,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 (eq read-char-by-name-display 'sections) + 'mule--ucs-names-by-group + 'mule--ucs-names-affixation)) + (display-sort-function + . ,(when (eq read-char-by-name-display 'code) + 'mule--ucs-names-by-code)) (category . unicode-name)) (complete-with-action action (ucs-names) string pred))))) (char --=-=-=--