aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/custom.el
diff options
context:
space:
mode:
authorMauro Aranda2021-05-10 13:33:32 +0200
committerLars Ingebrigtsen2021-05-10 13:33:32 +0200
commit779c615f333a01d11ab930b030d61545fb048f3d (patch)
tree493738307f960d58d525af7e1b825ec901dda12e /lisp/custom.el
parent5bedbe6b1d5f4b801abf91b4d023d5c4e66418f0 (diff)
downloademacs-779c615f333a01d11ab930b030d61545fb048f3d.tar.gz
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/custom.el')
-rw-r--r--lisp/custom.el39
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."
207 (put symbol 'custom-requests requests) 207 (put symbol 'custom-requests requests)
208 ;; Do the actual initialization. 208 ;; Do the actual initialization.
209 (unless custom-dont-initialize 209 (unless custom-dont-initialize
210 (funcall initialize symbol default)) 210 (funcall initialize symbol default)
211 ;; If there is a value under saved-value that wasn't saved by the user,
212 ;; reset it: we used that property to stash the value, but we don't need
213 ;; it anymore.
214 ;; This can happen given the following:
215 ;; 1. The user loaded a theme that had a setting for an unbound
216 ;; variable, so we stashed the theme setting under the saved-value
217 ;; property in `custom-theme-recalc-variable'.
218 ;; 2. Then, Emacs evaluated the defcustom for the option
219 ;; (e.g., something required the file where the option is defined).
220 ;; If we don't reset it and the user later sets this variable via
221 ;; Customize, we might end up saving the theme setting in the custom-file.
222 ;; See the test `custom-test-no-saved-value-after-customizing-option'.
223 (let ((theme (caar (get symbol 'theme-value))))
224 (when (and theme (not (eq theme 'user)) (get symbol 'saved-value))
225 (put symbol 'saved-value nil))))
211 (when buffer-local 226 (when buffer-local
212 (make-variable-buffer-local symbol))) 227 (make-variable-buffer-local symbol)))
213 (run-hooks 'custom-define-hook) 228 (run-hooks 'custom-define-hook)
@@ -1516,7 +1531,15 @@ See `custom-enabled-themes' for a list of enabled themes."
1516 (custom-push-theme prop symbol theme 'reset) 1531 (custom-push-theme prop symbol theme 'reset)
1517 (cond 1532 (cond
1518 ((eq prop 'theme-value) 1533 ((eq prop 'theme-value)
1519 (custom-theme-recalc-variable symbol)) 1534 (custom-theme-recalc-variable symbol)
1535 ;; We might have to reset the stashed value of the variable, if
1536 ;; no other theme is customizing it. Without this, loading a theme
1537 ;; that has a setting for an unbound user option and then disabling
1538 ;; it will leave this lingering setting for the option, and if then
1539 ;; Emacs evaluates the defcustom the saved-value might be used to
1540 ;; set the variable. (Bug#20766)
1541 (unless (get symbol 'theme-value)
1542 (put symbol 'saved-value nil)))
1520 ((eq prop 'theme-face) 1543 ((eq prop 'theme-face)
1521 ;; If the face spec specified by this theme is in the 1544 ;; If the face spec specified by this theme is in the
1522 ;; saved-face property, reset that property. 1545 ;; saved-face property, reset that property.
@@ -1565,8 +1588,16 @@ This function returns nil if no custom theme specifies a value for VARIABLE."
1565(defun custom-theme-recalc-variable (variable) 1588(defun custom-theme-recalc-variable (variable)
1566 "Set VARIABLE according to currently enabled custom themes." 1589 "Set VARIABLE according to currently enabled custom themes."
1567 (let ((valspec (custom-variable-theme-value variable))) 1590 (let ((valspec (custom-variable-theme-value variable)))
1568 (if valspec 1591 ;; We used to save VALSPEC under the saved-value property unconditionally,
1569 (put variable 'saved-value valspec) 1592 ;; but that is a recipe for trouble because we might end up saving session
1593 ;; customizations if the user loads a theme. (Bug#21355)
1594 ;; It's better to only use the saved-value property to stash the value only
1595 ;; if we really need to stash it (i.e., VARIABLE is void).
1596 (condition-case nil
1597 (default-toplevel-value variable) ; See if it doesn't fail.
1598 (void-variable (when valspec
1599 (put variable 'saved-value valspec))))
1600 (unless valspec
1570 (setq valspec (get variable 'standard-value))) 1601 (setq valspec (get variable 'standard-value)))
1571 (if (and valspec 1602 (if (and valspec
1572 (or (get variable 'force-value) 1603 (or (get variable 'force-value)