Subject: bug#28904: modes changed outside Customize

From: Mauro Aranda <[email-masked]>
Date: Mon, 24 Aug 2020 20:04:06 -0300

[email-masked] (Charles A. Roelli) writes:

>>>From emacs -q (26.0.90):
>
> M-x column-number-mode
> C-x z > Repeat it to turn it back off.
> M-x load-theme RET tango RET > Any theme will do.
>
> Notice that column numbers are turned on again in the mode line.  They
> should not be on.

I can reproduce this with latest master.

This was introduced in commit fccf278488785f482c7c50ac0713aa8f60dafbe9.
The issue is that we are pushing the new value to the user theme only if
it is not the saved-value or the standard-value.  So if the user ever goes
back
to one of those two values (in the recipe, by turning `column-number-mode'
off),
then we never store that value in the user theme.

And because we have the wrong value stored, loading a theme steps over
the user preference.

So I think the fix would be to keep the user theme in sync with the
actual value, at any time.
From b53149c821cbeb836b68f1e0c12c09e8226dbd1f Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Mon, 24 Aug 2020 09:24:28 -0300
Subject: [PATCH] Keep the user theme in sync when marking a variable as set

* lisp/custom.el (customize-mark-as-set): Keep the user theme in sync
  even if the new value of the variable is the saved-value or the
  standard-value.  If we don't do this, custom themes might end up
  stepping over the user preferences in a session.  (Bug#28904)
---
 lisp/custom.el | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lisp/custom.el b/lisp/custom.el
index db7f6a056d..7581457ce8 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -758,6 +758,9 @@ customize-mark-as-set
 	(progn (put symbol 'customized-value (list (custom-quote value)))
 	       (custom-push-theme 'theme-value symbol 'user 'set
 				  (custom-quote value)))
+      (custom-push-theme 'theme-value symbol 'user
+                         (if (get symbol 'saved-value) 'set 'reset)
+                         (custom-quote value))
       (put symbol 'customized-value nil))
     ;; Changed?
     (not (equal customized (get symbol 'customized-value)))))
-- 
2.28.0