unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Robert Weiner <rsw@gnu.org>
Cc: rswgnu@gmail.com, 23975@debbugs.gnu.org
Subject: bug#23975: 25.0.94: defcustom error message is wrong when :type field has a :match attribute
Date: Sun, 28 Jul 2019 13:12:25 +0200	[thread overview]
Message-ID: <87a7cyct0m.fsf@mouse.gnus.org> (raw)
In-Reply-To: <CA+OMD9hP+uAc-YJnf7VqX=Bu+FwGD-88-uEB8OxGpjfFxLvbWg@mail.gmail.com> (Robert Weiner's message of "Wed, 13 Jul 2016 16:03:28 -0400")

Robert Weiner <rsw@gnu.org> writes:

> Given a defcustom like:
>
> (defcustom bounded-num 999
>   "Positive, bounded number"
>   :type '(integer :match (lambda (widget value) (and (integerp value)
> (> value 0)
>       (< value 1000)))))
>
> When this variable is customized and a value of -5 is entered, the
> match function fails
> and the error signaled is:
>
>   (error "This field should contain an integer")
>
> which is wrong and not helpful.  Instead the error should display what
> the match function is and that the value failed to match.
>
> Secondarily, it would be nice if the type were checked before the match
> function were applied so that one did not need to add the (integerp
> value) test into the match function.

(I'm going through old Emacs bug reports that haven't received any
response.)

Both sound like good ideas, but the code here is rather convoluted.

So, for your defcustom (or "widget" at this point):

(widget-get w :match)
=> (lambda (widget value) (and (integerp value) (> value 0) (< value 1000)))

If that fails, then we get the error with

(widget-get w :type-error)
=> "This field should contain an integer"

So far so bad -- this means that custom doesn't actually call the
integerp check at all for defcustoms with an explicit :match.

Here's another defcustom without a custom :match:

(widget-get w2 :match)
=> widget-restricted-sexp-match

and that function does

(widget-get w2 :match-alternatives)
=> (integerp)

and then calls `integerp'.  Your defcustom also has this, but it's never
called:

(widget-get w :match-alternatives)
=> (integerp)

So this is all rather a mess.  It seems obvious that
(widget-get widget :match-alternatives) should always be called, but
it's not if you have an explicit :match, and my guess that doing so
might well break a lot of stuff.

As for the error message, we can't really fix that trivially either,
because you may have said :match widget-restricted-sexp-match or the
like, and then the error message is correct.  It sounds unlikely,
though, and we could add a hack that says that if :match is
widget-restricted-sexp-match, then we don't output the standard error
message but instead what's actually in :match, but that's...  hacky?

But possible.  Anybody have an opinion?

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





  reply	other threads:[~2019-07-28 11:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-13 20:03 bug#23975: 25.0.94: defcustom error message is wrong when :type field has a :match attribute Robert Weiner
2019-07-28 11:12 ` Lars Ingebrigtsen [this message]
2019-07-28 11:49   ` Andreas Schwab
2020-09-04 11:28 ` Mauro Aranda
2020-09-04 12:12   ` Lars Ingebrigtsen
2020-09-04 12:48 ` Mauro Aranda
2020-09-04 12:51   ` Lars Ingebrigtsen

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=87a7cyct0m.fsf@mouse.gnus.org \
    --to=larsi@gnus.org \
    --cc=23975@debbugs.gnu.org \
    --cc=rsw@gnu.org \
    --cc=rswgnu@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).