unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Mauro Aranda <maurooaranda@gmail.com>
To: "Omar Antolín Camarena" <omar.antolin@gmail.com>
Cc: 60712@debbugs.gnu.org
Subject: bug#60712: 28.2; customize-set-variable won't let you change the type of a choice
Date: Sun, 16 Jul 2023 09:18:54 -0300	[thread overview]
Message-ID: <8d7ea0a1-0847-3643-fa8e-7bfe1e066706@gmail.com> (raw)
In-Reply-To: <87zgaq2sy5.fsf@penguin>

Omar Antolín Camarena <omar.antolin@gmail.com> writes:

 > If you declare a user option as follows:
 >
 > (defcustom bool-or-alist '((a . 4) (b . 7))
 >   "A made up option to illustrate a problem."
 >   :type '(choice boolean (alist :key-type symbol :value-type integer)))
 >
 > And then run M-x customize-set-variable to change the value to t the
 > change fails with the message:
 >
 > widget-prompt-value: Value does not match alist type

I didn't manage to reproduce it with this recipe.  What I had to do
was, after emacs -Q:

(defcustom bool-or-alist '((a . 4) (b . 7))
   "A made up option to illustrate a problem."
   :type '(choice boolean (alist :key-type symbol :value-type integer)))

M-x customize-set-variable RET bool-or-alist

I get a prompt:
[boolean] [choice] Set customized value for bool-or-ailst to true:
If I answer y or n, there's no problem, bool-or-alist will be t or nil.

M-x customize-set-variable RET bool-or-alist

New prompt:
[alist] [choice] Set customized value for bool-or-alist to:
Here if you answer t, you get the message:
widget-prompt-value: Value does not match alist type

Which is not surprising, since t is not an alist and the prompt says its
expecting an alist.

What's surprising is that the prompt is choosing one of the two options
beforehand.  I mean, going back to the original definition and
re-evaluating, say that I want to use customize-set-variable to change
the alist.  I can't do that right away: I have to set it to t or nil,
and then execute customize-set-variable again to set it to an alist.
Not good.

 > I think the problem is that widget-choice-prompt-value figures which
 > branch of the choice the variable currenty has and then expects the new
 > type to be the same.

 > If you tag everything, then customize-set-variable works just fine:
 >
 > (defcustom bool-or-alist '((a . 4) (b . 7))
 >   "A made up option to illustrate a problem."
 >   :type '(choice (const :tag "Yes" t)
 >                  (const :tag "No" nil)
 >                  (alist :tag "An alist"
 >                         :key-type symbol :value-type integer)))
 >

Yes, but it's not because of the tags.  It's just that previously the
choice widget had two choice, and now it has three, and since there's at
least two options to pick (excluding the current),
widget-choice-prompt-value won't choose for you one of the options
beforehand.

We have this condition in widget-choice-prompt-value:
((and (= (length args) 2)
       (memq old args))
  (if (eq old (nth 0 args))
      (nth 1 args)
    (nth 0 args)))

ARGS holds the choices available in the choice widget and OLD has
the choice that matches the current value of the choice widget, before
the user enters a new one.  This branch has been in the code since like
forever, but I can't explain why it's good to have it.






  reply	other threads:[~2023-07-16 12:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-10 17:35 bug#60712: 28.2; customize-set-variable won't let you change the type of a choice Omar Antolín Camarena
2023-07-16 12:18 ` Mauro Aranda [this message]
2023-07-16 13:27   ` Mauro Aranda
2023-07-22 12:59     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8d7ea0a1-0847-3643-fa8e-7bfe1e066706@gmail.com \
    --to=maurooaranda@gmail.com \
    --cc=60712@debbugs.gnu.org \
    --cc=omar.antolin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).