Subject: Re: bug#77928: 31.0.50; ebcde0f90f6 (bug#77928) breaks :custom-face for themed faces

From: Steven Allen <[email-masked]>
Date: Sun, 08 Jun 2025 12:25:28 -0700

Michael Shields <[email-masked]> writes:

> I don't use themes either, but I can describe my use case.
>
> I refactored much of my Emacs config into use-package. Most of that went straightforwardly into :init, :bind, :hook, etc. Custom variables moved to :custom, and custom faces moved to :custom-face. But this caused some faces to change, because custom-set-faces effectively replaces the face definition, while :custom-face overlaid it.
>
> If I understand the history, :custom-face initially called custom-set-faces, so it behaved identically to having custom-set-faces in custom.el. But this confusingly resulted in :custom-face definitions being written to custom.el as if the user had configured them through M-x customize. https://github.com/jwiegley/use-package/pull/1004 fixed that, unintentionally also changing the semantics of :custom-face.
>
> With my patch applied, :custom-face should be equivalent in behavior to custom-set-faces, but without the settings appearing as if they were user-set.

I think I've found one of source of confusion: `custom-set-faces' DOES
overlay/merge faces, but only for themed faces. For unthemed (default)
faces, it resets the entire face spec (as you describe).

> I don't know how this should interact with themes. Maybe the right approach there is to define a new personal theme and configure faces there instead of using :custom-face. Or maybe it is simplest to call face-spec-set explicitly from :config.

The former (custom theme) sounds like what use-package does with :custom
(it defines a use-package theme). Maybe just implement :custom-face the same way :custom is
implemented? I.e.:

    (defun use-package-handler/:custom-face (name _keyword args rest state)
      (use-package-concat
       (if (bound-and-true-p use-package-use-theme)
           `((let ((custom--inhibit-theme-enable nil))
               ;; Declare the theme here so use-package can be required inside
               ;; eval-and-compile without warnings about unknown theme.
               (unless (memq 'use-package custom-known-themes)
                 (deftheme use-package)
                 (enable-theme 'use-package)
                 (setq custom-enabled-themes (remq 'use-package custom-enabled-themes)))
               (custom-theme-set-faces
                'use-package
                ,@(mapcar
                   #'(lambda (def)
                       (let ((face (nth 0 def))
                             (spec (nth 1 def))
                             (comment (nth 2 def)))
                         (unless (and comment (stringp comment))
                           (setq comment (format "Customized with use-package %s" name)))
                         `(backquote (,face ,spec nil ,comment))))
                   args))))
         (mapcar
          #'(lambda (def)
              (let ((face (nth 0 def))
                    (spec (nth 1 def))
                    (comment (nth 2 def)))
                (unless (and comment (stringp comment))
                  (setq comment (format "Customized with use-package %s" name)))
                `(custom-set-faces (backquote (,face ,spec t ,comment)))))
          args))
       (use-package-process-keywords name rest state)))