GNU bug report logs - #77928
[PATCH] use-package :custom-face is meant to behave like custom-set-face

Previous Next

Package: emacs;

Reported by: Michael Shields <shields <at> msrl.com>

Date: Sat, 19 Apr 2025 20:42:02 UTC

Severity: normal

Tags: patch

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Steven Allen <steven <at> stebalien.com>
To: Michael Shields <shields <at> msrl.com>, John Wiegley <johnw <at> gnu.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 77928 <at> debbugs.gnu.org
Subject: bug#77928: 31.0.50; ebcde0f90f6 (bug#77928) breaks :custom-face for themed faces
Date: Sun, 08 Jun 2025 15:46:38 -0700
Steven Allen <steven <at> stebalien.com> writes:
> 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)))

This version has a bug: if a new theme is enabled (e.g., the user
switches themes at runtime), that new theme will take precedence over
this "use-package" theme. This differs from the behavior of
`custom-set-faces' which ALWAYS takes precedence.

If there's a way to use `custom-set-faces' with no custom themes, that
would be better.

I CAN fix (hack) this with a hook to reapply the theme as follows:

    (defun use-package--reapply-theme (theme)
      (unless (or (memq theme '(use-package user))
                  ;; prevents recursion
                  (memq 'use-package custom-enabled-themes))
        (enable-theme 'use-package)
        (setq custom-enabled-themes (remq 'use-package custom-enabled-themes))))
    (add-hook 'enable-theme-functions #'use-package--reapply-theme)

This mimic's the behavior of the "user" theme (the theme used by
`custom-set-faces') in `enable-theme' (reproduced below):

    (defun enable-theme (theme)
      ...
      (unless (eq theme 'user)
        (setq custom-enabled-themes
    	  (cons theme (remq theme custom-enabled-themes)))
        ;; Give the `user' theme the highest priority.
        (enable-theme 'user))
      ;; Allow callers to react to the enabling.
      (run-hook-with-args 'enable-theme-functions theme))

HOWEVER, it will cause the "user" theme to be applied twice (because
we're calling `enable-theme' from within `enable-theme'), which isn't
great.




This bug report was last modified 43 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.