Subject: bug#15214: 24.3.50; `Revert This Session's Customization' does not do what it says

From: Mauro Aranda <[email-masked]>
Date: Mon, 30 Dec 2019 18:30:31 -0300

tags 15214 patch
thanks

Drew Adams <[email-masked]> writes:

> 1. emacs -Q
>
> M-x customize-option backup-by-copying
>
> Click Toggle, then State and Set For Current Session.
> You have changed the value.
>
> Click State and Revert This Session's Customization.
>
> The current value does not change back to what it was before you changed
> the setting for the session.  This session's customization was not
> reverted.  However, even though the value was not changed, you see the
> message "CHANGED outside Customize".

I can reproduce this in latest master and emacs-27 branch.

> 2. The State choice of Revert This Session's Customization is not even
> documented at (emacs) `Changing a Variable'.  Other State actions are
> documented.  So it's hard to tell whether #1 above is really a bug: it's
> not even clear what this menu item is supposed to do.

Current (emacs) Changing a Variable says:
‘Revert This Session's Customizations’
     This restores the value of the variable to the last saved value, if
     there was one.  Otherwise it restores the standard value.  It
     updates the text accordingly.

The function that runs for that option is custom-variable-reset-saved,
and the doc string of custom-variable-reset-saved says something similar.

The attached patch fixes custom-variable-reset-saved to do what it says
it does when the variable has no previous saved value.

Best regards,
Mauro.
From 2092fb0b9a36775e22efc5fd967a05f6e4bffbeb Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Mon, 30 Dec 2019 18:10:28 -0300
Subject: [PATCH] Reset to the standard value when reverting session's
 customization

* lisp/cus-edit.el (custom-variable-reset-saved): When there is no
previous saved value, reset to the standard value.  (Bug#15214)
---
 lisp/cus-edit.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 439667a..4fa6dfe 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -3038,8 +3038,11 @@ custom-variable-reset-saved
 	 (comment (get symbol 'saved-variable-comment)))
     (custom-variable-backup-value widget)
     (if (not (or saved-value comment))
-	;; If there is no saved value, remove the setting.
-	(custom-push-theme 'theme-value symbol 'user 'reset)
+        (progn
+	  ;; If there is no saved value, remove the setting.
+	  (custom-push-theme 'theme-value symbol 'user 'reset)
+          (funcall (or (get symbol 'custom-set) #'set-default) symbol
+                   (eval (car (get symbol 'standard-value)))))
       ;; Otherwise, apply the saved value.
       (put symbol 'variable-comment comment)
       (custom-push-theme 'theme-value symbol 'user 'set (car-safe saved-value))
-- 
2.7.4