emacs-diffs
[Top][All Lists]
Advanced

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

master b5316e1ddb7: read-face-name: Build common completion table for CR


From: Juri Linkov
Subject: master b5316e1ddb7: read-face-name: Build common completion table for CR and CRM
Date: Mon, 3 Feb 2025 13:33:18 -0500 (EST)

branch: master
commit b5316e1ddb728ab7502e2b2fffcc84e9c47316dd
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Juri Linkov <juri@linkov.net>

    read-face-name: Build common completion table for CR and CRM
    
    * lisp/faces.el (read-face-name): Build a common completion
    table for both `completing-read' and `completing-read-multiple'
    with completion metadata (bug#74865).
---
 lisp/faces.el | 40 +++++++++++++++++++---------------------
 1 file changed, 19 insertions(+), 21 deletions(-)

diff --git a/lisp/faces.el b/lisp/faces.el
index 5fe3ab1a294..dd8c24f5001 100644
--- a/lisp/faces.el
+++ b/lisp/faces.el
@@ -1137,19 +1137,30 @@ returned.  Otherwise, DEFAULT is returned verbatim."
     (let ((prompt (if default
                       (format-prompt prompt default)
                     (format "%s: " prompt)))
-          aliasfaces nonaliasfaces faces)
+          aliasfaces nonaliasfaces table)
       ;; Build up the completion tables.
       (mapatoms (lambda (s)
                   (if (facep s)
                       (if (get s 'face-alias)
                           (push (symbol-name s) aliasfaces)
                         (push (symbol-name s) nonaliasfaces)))))
+      (setq table
+            (completion-table-with-metadata
+             (completion-table-in-turn nonaliasfaces aliasfaces)
+             `((affixation-function
+                . ,(lambda (faces)
+                     (mapcar
+                      (lambda (face)
+                        (list face
+                              (concat (propertize read-face-name-sample-text
+                                                  'face face)
+                                      "\t")
+                              ""))
+                      faces))))))
       (if multiple
-          (progn
-            (dolist (face (completing-read-multiple
-                           prompt
-                           (completion-table-in-turn nonaliasfaces aliasfaces)
-                           nil t nil 'face-name-history default))
+          (let (faces)
+            (dolist (face (completing-read-multiple prompt table nil t nil
+                                                    'face-name-history 
default))
               ;; Ignore elements that are not faces
               ;; (for example, because DEFAULT was "all faces")
               (if (facep face) (push (if (stringp face)
@@ -1157,21 +1168,8 @@ returned.  Otherwise, DEFAULT is returned verbatim."
                                        face)
                                      faces)))
             (nreverse faces))
-        (let ((face (completing-read
-                     prompt
-                     (completion-table-with-metadata
-                      (completion-table-in-turn nonaliasfaces aliasfaces)
-                      `((affixation-function
-                        . ,(lambda (faces)
-                             (mapcar
-                              (lambda (face)
-                                (list face
-                                      (concat (propertize 
read-face-name-sample-text
-                                                          'face face)
-                                              "\t")
-                                      ""))
-                              faces)))))
-                     nil t nil 'face-name-history defaults)))
+        (let ((face (completing-read prompt table nil t nil
+                                     'face-name-history defaults)))
           (when (facep face) (if (stringp face)
                                  (intern face)
                                face)))))))



reply via email to

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