From: Juri Linkov <juri@linkov.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: larsi@gnus.org, 46240@debbugs.gnu.org
Subject: bug#46240: Sorting order of read-char-by-name
Date: Sat, 06 Feb 2021 21:35:18 +0200 [thread overview]
Message-ID: <87im75dm4t.fsf@mail.linkov.net> (raw)
In-Reply-To: <831rdvq84d.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 05 Feb 2021 09:36:02 +0200")
[-- Attachment #1: Type: text/plain, Size: 894 bytes --]
>> > 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':
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: read-char-by-name-group.patch --]
[-- Type: text/x-diff, Size: 4123 bytes --]
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
next prev parent reply other threads:[~2021-02-06 19:35 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
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 [this message]
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=87im75dm4t.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=46240@debbugs.gnu.org \
--cc=eliz@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.