GNU bug report logs - #21355
24.4; Loading a theme causes session customizations to be saved

Previous Next

Package: emacs;

Reported by: Greg Lucas <greg <at> glucas.net>

Date: Wed, 26 Aug 2015 21:05:03 UTC

Severity: normal

Tags: fixed, patch

Found in version 24.4

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 21355 in the body.
You can then email your comments to 21355 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#21355; Package emacs. (Wed, 26 Aug 2015 21:05:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Greg Lucas <greg <at> glucas.net>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 26 Aug 2015 21:05:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Greg Lucas <greg <at> glucas.net>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4; Loading a theme causes session customizations to be saved
Date: Wed, 26 Aug 2015 17:04:17 -0400
Loading a theme has the unexpected side of effect of making
customizations in the current session saved to the custom-file the next
time it is updated. 

I reproduced this problem by starting Emacs with an new empty user home
directory (since using -q would prevent saving customizations at all).

Then:

M-x customize-variable sentence-end-double-space -- toggle the value,
and Set for Current Session.
M-x load-theme deeper-blue
M-x customize-variable user-full-name -- set a value and Save for Future
Sessions. 

I would expect only the user-full-name to be saved, but the resulting
.emacs file contains:

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(sentence-end-double-space nil)
 '(user-full-name "Greg Lucas"))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )



From testing this I've found that at the time I call `load-theme` all
customizations made for the current session will get marked to be saved.
Changes made after load-theme behave as expected and do not get saved
unless I explicitly choose to save them.



In GNU Emacs 24.4.1 (i686-pc-mingw32)
 of 2014-10-20 on LEG570
Windowing system distributor `Microsoft Corp.', version 6.3.9600
Important settings:
  value of $LANG: ENU
  locale-coding-system: cp1252

Major mode: Emacs-Lisp

Minor modes in effect:
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
<lwindow> M-x c u s t o m i z e - v a r <tab> <return> 
s h o w - p a <tab> <tab> <tab> <C-backspace> - <backspace> 
<tab> <tab> <C-backspace> <C-backspace> <C-backspace> 
<tab> C-g C-g M-x c u s t - v <tab> a r <tab> <return> 
s e n t e n <tab> <tab> - d <tab> <return> <help-echo> 
<down-mouse-1> <mouse-1> <help-echo> <down-mouse-1> 
<help-echo> <help-echo> M-x l o a d - t h e m e <return> 
d e e <tab> <return> M-x c u s t o m i z e - v <tab> 
<return> s h o w - p a <tab> <C-backspace> <C-backspace> 
<C-backspace> u s e r <tab> f <tab> <return> <down-mouse-1> 
<mouse-1> G r e g SPC L u c a s <help-echo> <help-echo> 
<down-mouse-1> C-x C-f ~ / . e m <tab> <return> M-x 
e m a c s - r e <tab> <C-backspace> <C-backspace> r 
e p o <tab> r <tab> <return>

Recent messages:
Creating customization setup...done
To install your edits, invoke [State] and choose the Set operation
Creating customization items...
Creating customization items ...done
Resetting customization items...done
Creating customization setup...done
(New file)
Saving file c:/temp/emacs-home/.emacs...
Wrote c:/temp/emacs-home/.emacs [2 times]
Making completion list...

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils deeper-blue-theme help-mode help-fns cus-edit
easymenu cus-start cus-load wid-edit cl-loaddefs cl-lib time-date
tooltip electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
dos-w32 ls-lisp w32-common-fns disp-table w32-win w32-vars tool-bar dnd
fontset image regexp-opt fringe tabulated-list newcomment lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
w32notify w32 multi-tty emacs)

Memory information:
((conses 8 99251 6599)
 (symbols 32 19304 0)
 (miscs 32 270 184)
 (strings 16 15490 4166)
 (string-bytes 1 403422)
 (vectors 8 10810)
 (vector-slots 4 394593 5356)
 (floats 8 68 253)
 (intervals 28 353 19)
 (buffers 508 17))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21355; Package emacs. (Mon, 07 Sep 2020 19:52:02 GMT) Full text and rfc822 format available.

Message #8 received at 21355 <at> debbugs.gnu.org (full text, mbox):

From: Mauro Aranda <maurooaranda <at> gmail.com>
To: 21355 <at> debbugs.gnu.org
Cc: Greg Lucas <greg <at> glucas.net>
Subject: Re: bug#21355: 24.4; Loading a theme causes session customizations to
 be saved
Date: Mon, 7 Sep 2020 16:50:39 -0300
[Message part 1 (text/plain, inline)]
Greg Lucas <greg <at> glucas.net> writes:

> Loading a theme has the unexpected side of effect of making
> customizations in the current session saved to the custom-file the next
> time it is updated.
>
> I reproduced this problem by starting Emacs with an new empty user home
> directory (since using -q would prevent saving customizations at all).
>
> Then:
>
> M-x customize-variable sentence-end-double-space -- toggle the value,
> and Set for Current Session.
> M-x load-theme deeper-blue
> M-x customize-variable user-full-name -- set a value and Save for Future
> Sessions.
>
> I would expect only the user-full-name to be saved, but the resulting
> .emacs file contains:
>
> (custom-set-variables
>  ;; custom-set-variables was added by Custom.
>  ;; If you edit it by hand, you could mess it up, so be careful.
>  ;; Your init file should contain only one such instance.
>  ;; If there is more than one, they won't work right.
>  '(sentence-end-double-space nil)
>  '(user-full-name "Greg Lucas"))
> (custom-set-faces
>  ;; custom-set-faces was added by Custom.
>  ;; If you edit it by hand, you could mess it up, so be careful.
>  ;; Your init file should contain only one such instance.
>  ;; If there is more than one, they won't work right.
>  )
>
>
>
> From testing this I've found that at the time I call `load-theme` all
> customizations made for the current session will get marked to be saved.
> Changes made after load-theme behave as expected and do not get saved
> unless I explicitly choose to save them.

This one is really tricky.

When saving the variables to the custom-file with
custom-save-variables, we are interested in the symbols that have a
non-nil saved-value property and that don't have any theme applied:
(get symbol 'theme-value) ==> nil
or have the user theme preference applied:
(caar (get symbol 'theme-value)) ==> 'user

So we shouldn't let those combinations happen by accident.

The offending code is in custom-theme-recalc-variable: when there is a
custom theme that specifies a value for the variable, it puts that into
the 'saved-value property.  And custom-theme-recalc-variable is called
when enabling or disabling a theme.  So what happens in the recipe is:
- The user customizes some variable, so now:
(get VARIABLE 'theme-value) ==> ((user SETTING))
(get VARIABLE 'saved-value) ==> nil

- Then the user loads a theme with M-x load-theme.  So we enable it, and
then we give the priority to the user, so we re-enable the user theme.
When we enable the user theme, we end up with:
(get VARIABLE 'theme-value) ==> ((user SETTING))
(get VARIABLE 'saved-value) ==> (SETTING)

- If later in the session `custom-save-all' runs, then we save that
setting by mistake.

The code that depends on that side-effect of
custom-theme-recalc-variable is the custom-initialize-* functions (at
least in custom.el).  Those functions need to know if there is one value
stashed for the variable, to set it accordingly when initializing it.
And we stash the value when we load the custom-file or when loading a
theme.  So we are using the saved-value property for stashing this
value, which seems unfortunate to me.

Furthermore, there are some other scenarios where the bug happens:
1. Suppose we load a theme that has a setting for a bound variable.
Then we have:
(get VARIABLE 'theme-value) ==> ((THEME THEME-SETTING))
(get VARIABLE 'saved-value) ==> (THEME-SETTING)

Since THEME is not the user theme, we are not saving it in
`custom-save-all'.  But, when we disable the theme we have:
(get VARIABLE 'theme-value) ==> nil
(get VARIABLE 'saved-value) ==> (THEME-SETTING)

So if later custom-save-all runs, we lose again.

2. Now say we load a theme that has a setting for a variable that is
initially void in our session.
(get VARIABLE 'theme-value) ==> ((THEME THEME-SETTING))
(get VARIABLE 'saved-value) ==> (THEME-SETTING)

And then Emacs finds the option.  Then:
VARIABLE ==> THEME-SETTING
(get VARIABLE 'theme-value) ==> ((THEME THEME-SETTING))
(get VARIABLE 'saved-value) ==> (THEME-SETTING)

So, that shows that stashing the value worked.  But say we customize the
variable for the session:
VARIABLE ==> OUR-SETTING
(get VARIABLE 'theme-value) ==> ((user OUR-SETTING) (THEME THEME-SETTING))
(get VARIABLE 'saved-value) ==> (THEME-SETTING)

And we lose again.


I think that if we want to keep stashing the value under the
saved-value property, we could try to stash the value only if we need
to.  That is, if default-toplevel-value errors out, which would mean
custom-initialize-* will need to know if there is a saved-value.  But
then we have to make some tricks to reset the saved-value if we need
to.

I hope this analysis is helpful, I tried to keep it as short as I
could.
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21355; Package emacs. (Tue, 08 Sep 2020 12:33:02 GMT) Full text and rfc822 format available.

Message #11 received at 21355 <at> debbugs.gnu.org (full text, mbox):

From: Mauro Aranda <maurooaranda <at> gmail.com>
To: 21355 <at> debbugs.gnu.org
Cc: Greg Lucas <greg <at> glucas.net>
Subject: Re: bug#21355: 24.4; Loading a theme causes session customizations to
 be saved
Date: Tue, 8 Sep 2020 09:32:30 -0300
[Message part 1 (text/plain, inline)]
I attach a patch with three tests that demonstrate the bug.
[Message part 2 (text/html, inline)]
[0001-Add-tests-demonstrating-Bug-21355.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21355; Package emacs. (Fri, 06 Nov 2020 12:33:02 GMT) Full text and rfc822 format available.

Message #14 received at 21355 <at> debbugs.gnu.org (full text, mbox):

From: Mauro Aranda <maurooaranda <at> gmail.com>
To: 21355 <at> debbugs.gnu.org
Cc: Greg Lucas <greg <at> glucas.net>
Subject: Re: bug#21355: 24.4; Loading a theme causes session customizations to
 be saved
Date: Fri, 6 Nov 2020 09:31:43 -0300
[Message part 1 (text/plain, inline)]
Mauro Aranda <maurooaranda <at> gmail.com> writes:

> I attach a patch with three tests that demonstrate the bug.

And now I attach a patch to fix this, with the three tests updated.
[Message part 2 (text/html, inline)]
[0001-Avoid-saving-session-customizations-in-the-custom-fi.patch (text/x-patch, attachment)]

Added tag(s) patch. Request was from Mauro Aranda <maurooaranda <at> gmail.com> to control <at> debbugs.gnu.org. (Fri, 06 Nov 2020 12:33:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21355; Package emacs. (Mon, 10 May 2021 11:36:01 GMT) Full text and rfc822 format available.

Message #19 received at 21355 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Mauro Aranda <maurooaranda <at> gmail.com>
Cc: Greg Lucas <greg <at> glucas.net>, 21355 <at> debbugs.gnu.org
Subject: Re: bug#21355: 24.4; Loading a theme causes session customizations
 to be saved
Date: Mon, 10 May 2021 13:35:14 +0200
Mauro Aranda <maurooaranda <at> gmail.com> writes:

> And now I attach a patch to fix this, with the three tests updated.

If I'm reading that patch correctly, it looks good to me, so I've now
applied it to Emacs 28.  It didn't apply cleanly, so I fixed the patch
up manually, and hopefully that didn't lead to any merge errors.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) fixed. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 10 May 2021 11:36:02 GMT) Full text and rfc822 format available.

bug marked as fixed in version 28.1, send any further explanations to 21355 <at> debbugs.gnu.org and Greg Lucas <greg <at> glucas.net> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Mon, 10 May 2021 11:36:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#21355; Package emacs. (Tue, 11 May 2021 11:54:01 GMT) Full text and rfc822 format available.

Message #26 received at 21355 <at> debbugs.gnu.org (full text, mbox):

From: Mauro Aranda <maurooaranda <at> gmail.com>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: greg <at> glucas.net, 21355 <at> debbugs.gnu.org
Subject: Re: bug#21355: 24.4; Loading a theme causes session customizations
 to be saved
Date: Tue, 11 May 2021 08:53:14 -0300
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Mauro Aranda <maurooaranda <at> gmail.com> writes:
>
>> And now I attach a patch to fix this, with the three tests updated.
>
> If I'm reading that patch correctly, it looks good to me, so I've now
> applied it to Emacs 28.  It didn't apply cleanly, so I fixed the patch
> up manually, and hopefully that didn't lead to any merge errors.

Thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 09 Jun 2021 11:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 23 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.