diff options
author | Mauro Aranda <maurooaranda@gmail.com> | 2021-05-10 13:33:32 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-05-10 13:33:32 +0200 |
commit | 779c615f333a01d11ab930b030d61545fb048f3d (patch) | |
tree | 493738307f960d58d525af7e1b825ec901dda12e /lisp | |
parent | 5bedbe6b1d5f4b801abf91b4d023d5c4e66418f0 (diff) | |
download | emacs-779c615f333a01d11ab930b030d61545fb048f3d.tar.gz emacs-779c615f333a01d11ab930b030d61545fb048f3d.tar.bz2 emacs-779c615f333a01d11ab930b030d61545fb048f3d.zip |
Avoid saving session customizations in the custom-file
* lisp/custom.el (custom-theme-recalc-variable): Only stash theme
settings for void variables.
(custom-declare-variable): After initializing a variable, unstash a
theme setting, if present.
(disable-theme): When disabling a theme, maybe unstash a theme
setting.
* test/lisp/custom-resources/custom--test-theme.el: Add two settings
for testing the fix.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/custom.el | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/lisp/custom.el b/lisp/custom.el index 614f8cf822d..078e3a8cf8e 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -207,7 +207,22 @@ set to nil, as the value is no longer rogue." (put symbol 'custom-requests requests) ;; Do the actual initialization. (unless custom-dont-initialize - (funcall initialize symbol default)) + (funcall initialize symbol default) + ;; If there is a value under saved-value that wasn't saved by the user, + ;; reset it: we used that property to stash the value, but we don't need + ;; it anymore. + ;; This can happen given the following: + ;; 1. The user loaded a theme that had a setting for an unbound + ;; variable, so we stashed the theme setting under the saved-value + ;; property in `custom-theme-recalc-variable'. + ;; 2. Then, Emacs evaluated the defcustom for the option + ;; (e.g., something required the file where the option is defined). + ;; If we don't reset it and the user later sets this variable via + ;; Customize, we might end up saving the theme setting in the custom-file. + ;; See the test `custom-test-no-saved-value-after-customizing-option'. + (let ((theme (caar (get symbol 'theme-value)))) + (when (and theme (not (eq theme 'user)) (get symbol 'saved-value)) + (put symbol 'saved-value nil)))) (when buffer-local (make-variable-buffer-local symbol))) (run-hooks 'custom-define-hook) @@ -1516,7 +1531,15 @@ See `custom-enabled-themes' for a list of enabled themes." (custom-push-theme prop symbol theme 'reset) (cond ((eq prop 'theme-value) - (custom-theme-recalc-variable symbol)) + (custom-theme-recalc-variable symbol) + ;; We might have to reset the stashed value of the variable, if + ;; no other theme is customizing it. Without this, loading a theme + ;; that has a setting for an unbound user option and then disabling + ;; it will leave this lingering setting for the option, and if then + ;; Emacs evaluates the defcustom the saved-value might be used to + ;; set the variable. (Bug#20766) + (unless (get symbol 'theme-value) + (put symbol 'saved-value nil))) ((eq prop 'theme-face) ;; If the face spec specified by this theme is in the ;; saved-face property, reset that property. @@ -1565,8 +1588,16 @@ This function returns nil if no custom theme specifies a value for VARIABLE." (defun custom-theme-recalc-variable (variable) "Set VARIABLE according to currently enabled custom themes." (let ((valspec (custom-variable-theme-value variable))) - (if valspec - (put variable 'saved-value valspec) + ;; We used to save VALSPEC under the saved-value property unconditionally, + ;; but that is a recipe for trouble because we might end up saving session + ;; customizations if the user loads a theme. (Bug#21355) + ;; It's better to only use the saved-value property to stash the value only + ;; if we really need to stash it (i.e., VARIABLE is void). + (condition-case nil + (default-toplevel-value variable) ; See if it doesn't fail. + (void-variable (when valspec + (put variable 'saved-value valspec)))) + (unless valspec (setq valspec (get variable 'standard-value))) (if (and valspec (or (get variable 'force-value) |