Subject: bug#76685: 30.1; custom--inhibit-theme-enable

From: Mauro Aranda <[email-masked]>
Date: Fri, 7 Mar 2025 06:26:14 -0300

João Guerra <[email-masked]> writes:

 >> So the use case would be:
 >> The user already loaded and enabled a theme (via load-theme and
 >> enable-theme) and then, while the theme is enabled, he/she wants to
 >> reevaluate a custom-theme-set-faces and see its effect immediately?
 >
 > That's the main use case indeed. Currently, the user needs to
 > re-enable the theme after evaluating their custom-theme-set-faces. If
 > they are experimenting with themes this becomes a bit cumbersome after
 > a while. What I have been doing and seen in other configurations is
 > `(setq custom--inhibit-theme-enable nil)`, so I was wondering if it
 > would be desirable to expose this functionality somehow to the user.
 >

The attached patch adds support for this, but without exposing
custom--inhibit-theme-enable, because it doesn't sound to me like a good
idea.

Opinions?
From f675ed7b61a12cad0dec8e99df81bc2b03920f40 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Thu, 6 Mar 2025 06:55:16 -0300
Subject: [PATCH] Allow changing theme settings without reloading it

* lisp/custom.el (custom--should-apply-setting): Return non-nil
for an enabled theme.  Provide docstring.  This allows for users
to reevaluate a custom-theme-set-* function and see the settings
applied right away.  (Bug#76685)
(custom--inhibit-theme-enable): Adapt docstring.
---
 lisp/custom.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/custom.el b/lisp/custom.el
index 5360c397c59..d309754ab9b 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -901,7 +901,15 @@ custom-check-theme
     (error "Unknown theme `%s'" theme)))
 
 (defun custom--should-apply-setting (theme)
-  (or (null custom--inhibit-theme-enable)
+  "Non-nil if settings for the theme THEME should apply immediately.
+
+Theme settings apply immediately if:
+- THEME is already enabled.
+- THEME is being enabled via `enable-theme' or an interactive call to
+  `load-theme'.
+- THEME is the `user' theme."
+  (or (memq theme custom-enabled-themes)
+      (null custom--inhibit-theme-enable)
       (and (eq custom--inhibit-theme-enable 'apply-only-user)
            (eq theme 'user))))
 
@@ -1235,6 +1243,10 @@ custom-theme-load-path
 
 (defvar custom--inhibit-theme-enable 'apply-only-user
   "Whether the custom-theme-set-* functions act immediately.
+
+If the theme argument for those functions is an already enabled theme,
+the theme settings always apply immediately, ignoring this variable.
+
 If nil, `custom-theme-set-variables' and `custom-theme-set-faces'
 change the current values of the given variable or face.  If
 t, they just make a record of the theme settings.  If the
-- 
2.34.1