[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] `completing-read`: Add `group-function` support to completio

From: Juri Linkov
Subject: Re: [PATCH] `completing-read`: Add `group-function` support to completion metadata (REVISED PATCH VERSION 2)
Date: Sun, 09 May 2021 21:05:15 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>>   (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."
>>   =====================
>> It seems a new function is needed to sort groups, e.g. `group-sort-function`.
> I think whether the groups should be sorted alphabetically or "by order
> of appearance" can be a choice made by the UI rather than by the
> completion-table.

Then this patch adds a new option read-char-by-name-group-sort,
instead of read-char-by-name-group now replaced by completions-group:

diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index b99db46e45..5a7e417b8e 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -3088,35 +3088,14 @@ mule--ucs-names-affixation
               (list name (concat (if char (list char) " ") "\t") "")))
-(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-group (action arg)
+  (pcase action
+    ('title (let ((script (aref char-script-table (gethash arg ucs-names))))
+              (if script (symbol-name script) "ungrouped")))
+    ('transform arg)
+    ('sort (if read-char-by-name-group-sort
+               (sort arg (lambda (a b) (string< (car a) (car b))))
+             arg))))
 (defun char-from-name (string &optional ignore-case)
   "Return a character as a number from its Unicode name STRING.
@@ -3148,11 +3127,12 @@ read-char-by-name-sort
   :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
+(defcustom read-char-by-name-group-sort nil
+  "How to sort groups of characters for `read-char-by-name' completion.
+When t, sort sections of Unicode blocks alphabetically."
+  :type '(choice
+          (const :tag "Unsorted group names" nil)
+          (const :tag "Group names sorted alphabetically" t))
   :group 'mule
   :version "28.1")
@@ -3169,8 +3149,9 @@ read-char-by-name
 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.
+The options `read-char-by-name-sort', `completions-group', and
+`read-char-by-name-group-sort' define the sorting order of completion
+characters, how to group them, and how to sort groups.
 Accept a name like \"CIRCULATION FUNCTION\", a hexadecimal
 number like \"2A10\", or a number in hash notation (e.g.,
@@ -3189,10 +3170,11 @@ read-char-by-name
                    . ,(when (eq read-char-by-name-sort 'code)
+                  (group-function
+                   . ,(when completions-group
+                        #'mule--ucs-names-group))
-                   . ,(if read-char-by-name-group
-                           #'mule--ucs-names-group
-                         #'mule--ucs-names-affixation))
+                   . ,#'mule--ucs-names-affixation)
                   (category . unicode-name))
               (complete-with-action action (ucs-names) string pred)))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]