emacs-devel
[Top][All Lists]
Advanced

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

Re: on helm substantial differences


From: Juri Linkov
Subject: Re: on helm substantial differences
Date: Fri, 20 Nov 2020 11:24:24 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> BTW, using `affix-function' also makes it possible to group completions,
> then the prefix of the first completion in the group could contain
> a group header with group name.

'mule--ucs-names-annotation' has this comment:

  ;; FIXME: It would be much better to add this annotation before rather than
  ;; after the char name, so the annotations are aligned.

With `affix-function' it's possible to add the char before the char name.
Adding groups is also simple (I recall that Richard asked to group by blocks).

PNG image

diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el
index d361971a1f..f536c10a13 100644
--- a/lisp/international/mule-cmds.el
+++ b/lisp/international/mule-cmds.el
@@ -3092,6 +3092,37 @@ mule--ucs-names-annotation
   (let ((char (gethash name ucs-names)))
     (when char (format " (%c)" char))))
 
+(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.
@@ -3138,8 +3169,10 @@ read-char-by-name
           prompt
           (lambda (string pred action)
             (if (eq action 'metadata)
-                '(metadata
-                  (annotation-function . mule--ucs-names-annotation)
+                `(metadata
+                  ,(if completions-detailed
+                        '(affix-function . mule--ucs-names-by-group)
+                      '(annotation-function . mule--ucs-names-annotation))
                   (category . unicode-name))
               (complete-with-action action (ucs-names) string pred)))))
         (char

reply via email to

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