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.
This commit is contained in:
Mauro Aranda 2025-03-09 09:22:29 -03:00
parent 5890ee840e
commit 203747b87f
2 changed files with 18 additions and 1 deletions

View file

@ -384,6 +384,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

View file

@ -901,7 +901,15 @@ to the front of this list.")
(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 @@ external packages). For manual user customizations, use
(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