Subject: bug#12864: 24.3.50; bad & confusing Customize `State' Menu behavior

From: Mauro Aranda <[email-masked]>
Date: Tue, 1 Sep 2020 13:02:55 -0300

Drew Adams <[email-masked]> writes:

> emacs -Q
>
> M-x customize-option delete-old-versions
>
> Value Menu: Leave
>
> State: Revert This Session's Customization
>
> The State is now back to STANDARD, which is correct.
>
> In the State menu, this item is not dimmed, but should be, since there
> should be no backup value different from the original value (Ask): Set
> to Backup Value.

Would it make sense to guard against backing up a value, if it's the
same as the new one? That way, Set to Backup Value would be disabled in
this situation.

> Choose Set to Backup Value anyway.  The State now shows "SET for current
> session only, which is incorrect (at best misleading).

I think this is a bug in `custom-variable-state': the first cond clause
doesn't check if value is equal to the standard-value, so it just
returns 'set.  It should check for it and return the correct state.

> The State menu now shows items Set to Backup Value and Revert This
> Session's Customization, both of which are incorrect and misleading.
> (The current value is the standard value, and we reverted to it.

Doing the two fixes above will fix this...

> Choose Revert This Session's Customization anyway.
>
> State now says CHANGED outside Customize, which is 100% wrong.  And the
> State menu shows Undo Edits, Revert This Session's Customization, and
> Set to Backup Value, all of which are wrong (and confusing).

...But this message can still appear when it shouldn't:
emacs -Q
M-x customize-option RET delete-old-versions
Set the variable to Delete, for the current session.
Set to Backup Value, to bring back the standard value of
delete-old-versions.
Then Revert This Session's Customization.

This is a bug in `custom-variable-reset-saved': it is not resetting the
'variable-comment property of the variable when there is no saved-value,
and that confuses `custom-variable-state'.

> Choose Undo Edits anyway.  It has no visible effect - State and its menu
> stay the same.  Again, confusing.
>
> Choose Set to Backup Value anyway.
>
> State now says SET for current session only, which is (still) wrong.
> And the same menu items are available, except Undo Edits.  Choosing Set
> to Backup Value again has no visible effect.  Choosing Revert This
> Session's Customization has the same incorrect effect as before (adds
> Undo Edits to the menu and changes State to CHANGED outside Customize.
>

I think this is just a consequence of the above three bugs.  IOW, no new
bug here.

I'm not sure how to proceed here: should I send different patches for
the bugs, or put the fixes altogether in one patch?