emacs-devel
[Top][All Lists]
Advanced

[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)
Date: Thu, 29 Apr 2021 19:20:04 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> You can try the patch with the following settings and execute
> `xref-find-references` for example (M-?).

I tried to use your patch to implement grouping for read-char-by-name.
It helped to greatly reduce the size of mule--ucs-names-group
from 30 lines to just 3 lines that is a big win.

OTOH, it highlighted the shortcomings of amalgamating both
grouping and transforming in the same function:
mule--ucs-names-group doesn't need to provide transformation,
because the same affixation-function is used for both
grouping and non-grouping completions.  So for such cases
handling an additional arg `transform` is an extra burden:

diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index b99db46e45..cb5770bdbe 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -3088,35 +3088,11 @@ mule--ucs-names-affixation
               (list name (concat (if char (list 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-group (name transform)
+  (if transform
+      name
+    (let ((script (aref char-script-table (gethash name ucs-names))))
+      (if script (symbol-name script) "ungrouped"))))
 
 (defun char-from-name (string &optional ignore-case)
   "Return a character as a number from its Unicode name STRING.
@@ -3148,7 +3124,7 @@ read-char-by-name-sort
   :group 'mule
   :version "28.1")
 
-(defcustom read-char-by-name-group nil
+(defcustom read-char-by-name-group t
   "How to group characters for `read-char-by-name' completion.
 When t, split characters to sections of Unicode blocks
 sorted alphabetically."
@@ -3180,6 +3156,8 @@ read-char-by-name
   (let* ((enable-recursive-minibuffers t)
         (completion-ignore-case t)
         (completion-tab-width 4)
+        (completions-group read-char-by-name-group)
+        (completions-format (if read-char-by-name-group 'one-column 
completions-format))
         (input
          (completing-read
           prompt
@@ -3189,10 +3167,11 @@ read-char-by-name
                   (display-sort-function
                    . ,(when (eq read-char-by-name-sort 'code)
                          #'mule--ucs-names-sort-by-code))
+                  (group-function
+                   . ,(when read-char-by-name-group
+                        #'mule--ucs-names-group))
                   (affixation-function
-                   . ,(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)))))
         (char

reply via email to

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