From: Juri Linkov <juri@linkov.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 46240@debbugs.gnu.org
Subject: bug#46240: Sorting order of read-char-by-name
Date: Thu, 04 Feb 2021 11:32:27 +0200 [thread overview]
Message-ID: <87zh0kw4n1.fsf@mail.linkov.net> (raw)
In-Reply-To: <87lfc4gtam.fsf@gnus.org> (Lars Ingebrigtsen's message of "Thu, 04 Feb 2021 08:56:33 +0100")
[-- Attachment #1: Type: text/plain, Size: 1433 bytes --]
>> 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?
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: read-char-by-name-display.patch --]
[-- Type: text/x-diff, Size: 3277 bytes --]
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
next prev parent reply other threads:[~2021-02-04 9:32 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zh0kw4n1.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=46240@debbugs.gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.