From ea550488233833baafda90a3f258f96953381274 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Sun, 17 Nov 2024 17:49:49 -0500 Subject: [PATCH] * cus-face.el: Provide completion for font families (bug#74362) * 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. --- etc/NEWS | 2 ++ lisp/cus-edit.el | 22 ++++++++++++++++++++++ lisp/cus-face.el | 3 ++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/etc/NEWS b/etc/NEWS index cb2ba2a78ff..55487aeb3a6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -167,6 +167,8 @@ GNU ELPA instead. This inherits from the 'header-line' face, but is the face actually used on the header lines (along with 'header-line-inactive'). +** In 'customize-face', the "Font family" attribute now supports completion. + * Editing Changes in Emacs 31.1 diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 8eba4270bcb..12d9315c52b 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -3425,6 +3425,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: diff --git a/lisp/cus-face.el b/lisp/cus-face.el index d0a1a66e29f..478092c30cb 100644 --- a/lisp/cus-face.el +++ b/lisp/cus-face.el @@ -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"