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

From: Mauro Aranda <[email-masked]>
Date: Fri, 7 Mar 2025 08:47:20 -0300

On 7/3/25 08:30, Eli Zaretskii wrote:
 >> Cc: [email-masked]
 >> Date: Fri, 7 Mar 2025 06:26:14 -0300
 >> From: Mauro Aranda <[email-masked]>
 >>
 >> 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?
 >
 > Since this has user-facing aspects, I think the effects of this change
 > should be called out in NEWS.

Makes sense.  Here's an updated patch.

From 59ab02c78cd1c7f2efbb343a058d02cdf086c430 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.

* etc/NEWS: Announce the new behavior.
---
 etc/NEWS       |  5 +++++
 lisp/custom.el | 14 +++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 258f0dcc4ba..5c3a99ecfe9 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -376,6 +376,11 @@ to wrong results in some cases.  We believe that it is no longer useful;
 please contact us if you still need it for some reason.
 
 ** 'byte-compile-cond-use-jump-table' is now obsolete.
+---
+** Modified settings for an enabled theme now apply immediately.
+Evaluating a custom-theme-set-faces or custom-theme-set-variables
+call for an enabled theme causes the settings to apply immediately,
+without a need to re-load the theme.
 
 
 * Editing Changes in Emacs 31.1
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