so e.g. like 'C-x 8 [' inserts a left single quotation mark,
'C-x \ [' does the same.
+---
+*** New user options 'read-char-by-name-sort' and 'read-char-by-name-group'.
+'read-char-by-name-sort' defines the sorting order of characters for
+completion of 'C-x 8 RET TAB' and can be customized to sort them
+by codepoints instead of character names by default. The 't' value of
+'read-char-by-name-group' groups the characters for completion of
+'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
(puthash "BELL (BEL)" ?\a names)
(setq ucs-names names))))
+(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 mule--ucs-names-affixation (names)
(mapcar (lambda (name)
(let ((char (gethash name ucs-names)))
(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 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.
ignore-case))
code)))))))
+(defcustom read-char-by-name-sort nil
+ "How to sort characters for `read-char-by-name' completion.
+Defines the sorting order either by character names or their codepoints."
+ :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 t, 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
the characters whose names include that substring, not necessarily
at the beginning of the name.
+The options `read-char-by-name-sort' and `read-char-by-name-group'
+define the sorting order of completion characters and how to group them.
+
Accept a name like \"CIRCULATION FUNCTION\", a hexadecimal
number like \"2A10\", or a number in hash notation (e.g.,
\"#x2a10\" for hex, \"10r10768\" for decimal, or \"#o25020\" for
prompt
(lambda (string pred action)
(if (eq action 'metadata)
- '(metadata
- (affixation-function . mule--ucs-names-affixation)
+ `(metadata
+ (display-sort-function
+ . ,(when (eq read-char-by-name-sort 'code)
+ 'mule--ucs-names-sort-by-code))
+ (affixation-function
+ . ,(if read-char-by-name-group
+ 'mule--ucs-names-group
+ 'mule--ucs-names-affixation))
(category . unicode-name))
(complete-with-action action (ucs-names) string pred)))))
(char