]> git.eshelyaron.com Git - emacs.git/commitdiff
* cus-face.el: Provide completion for font families (bug#74362)
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 17 Nov 2024 22:49:49 +0000 (17:49 -0500)
committerEshel Yaron <me@eshelyaron.com>
Wed, 20 Nov 2024 16:16:04 +0000 (17:16 +0100)
* lisp/cus-edit.el (custom-face--font-cache-timeout): New var.
(custom-face--font-completion): New function.
* lisp/cus-face.el (custom-face-attributes): Use it.

(cherry picked from commit ea550488233833baafda90a3f258f96953381274)

etc/NEWS
lisp/cus-edit.el
lisp/cus-face.el

index be3209f2ca28b344c572b0ad1b4670470922d542..19cbc360332abe8ce74cf903795ec8e780cd2e8a 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -119,6 +119,8 @@ These inherit from the 'header-line' face, but the faces actually used
 on the header lines are now these two: the selected window uses
 'header-line-active', non-selected windows use 'header-line-inactive'.
 
+** In 'customize-face', the "Font family" attribute now supports completion.
+
 \f
 * Editing Changes in Emacs 31.1
 
index 80ec1ee05fa365e52ad5c4413e74e993acc5c706..e6aa65a7113574f383edc5fd0c6d115cee0d11a3 100644 (file)
@@ -3486,6 +3486,28 @@ to switch between two values."
 
 ;;; The `custom-face-edit' Widget.
 
+(defvar custom-face--font-cache-timeout 60
+  "Refresh the cache of font families after at most this many seconds.")
+
+(defalias 'custom-face--font-completion
+  (let ((lastlist nil)
+        (lasttime nil)
+        (lastframe nil))
+    (completion-table-case-fold
+     (completion-table-dynamic
+      (lambda (_string)
+        ;; Flush the cache timeout after a while.
+        (let ((time (float-time)))
+         (if (and lastlist (eq (selected-frame) lastframe)
+                  (> custom-face--font-cache-timeout (- time lasttime)))
+             lastlist
+           ;; (message "last list time: %s" (if lasttime (- time lasttime)))
+           (setq lasttime time)
+           (setq lastframe (selected-frame))
+           (setq lastlist
+                 (nconc (mapcar #'car face-font-family-alternatives)
+                        (font-family-list))))))))))
+
 (define-widget 'custom-face-edit 'checklist
   "Widget for editing face attributes.
 The following properties have special meanings for this widget:
index d0a1a66e29fbbdaab9f2eaccf47d7c6205960040..478092c30cbe2b3a2b5e708c6fde34062607a1aa 100644 (file)
@@ -48,7 +48,8 @@
 (defconst custom-face-attributes
   `((:family
      (string :tag "Font Family"
-            :help-echo "Font family or fontset alias name."))
+            :completions custom-face--font-completion
+            :help-echo "Font family or fontset alias name (with completion)."))
 
     (:foundry
      (string :tag "Font Foundry"