all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#73098: setopt float warning unexpected
@ 2024-09-07 13:14 Ship Mints
  2024-09-08  6:06 ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Ship Mints @ 2024-09-07 13:14 UTC (permalink / raw)
  To: 73098

[-- Attachment #1: Type: text/plain, Size: 614 bytes --]

This one bit me yesterday on Emacs 29.3 as I was revising my init file (for
the thousandth time this week).

As setopt becomes more widely recommended, people will likely encounter
situations like the below where they expect constant numeric types to be
coerced.

(defcustom temp-float "Float"
  "Float type."
  :type 'float)

(setopt temp-float 2.0) ; works
(setopt temp-float 2) ; Warning (emacs): Value '2' does not match type float

-Stephane

P.S. I reported a bug to Prot as some much more complex modus defcustom
type definitions seem either themselves broken or setopt needs some work to
accommodate them.

[-- Attachment #2: Type: text/html, Size: 1328 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-07 13:14 bug#73098: setopt float warning unexpected Ship Mints
@ 2024-09-08  6:06 ` Eli Zaretskii
  2024-09-08 10:59   ` Ship Mints
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-08  6:06 UTC (permalink / raw)
  To: Ship Mints; +Cc: 73098

> From: Ship Mints <shipmints@gmail.com>
> Date: Sat, 7 Sep 2024 09:14:54 -0400
> 
> This one bit me yesterday on Emacs 29.3 as I was revising my init file (for the thousandth time this week).
> 
> As setopt becomes more widely recommended, people will likely encounter situations like the below where they
> expect constant numeric types to be coerced. 
> 
> (defcustom temp-float "Float"
>   "Float type."
>   :type 'float)
> 
> (setopt temp-float 2.0) ; works
> (setopt temp-float 2) ; Warning (emacs): Value '2' does not match type float

If you are going to allow integer values, shouldn't :type be 'number,
not 'float?  The documentation of 'float says:

  ‘float’
       The value must be floating point.

"Must be floating point."  The value 2 isn't.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-08  6:06 ` Eli Zaretskii
@ 2024-09-08 10:59   ` Ship Mints
  2024-09-08 11:08     ` Eli Zaretskii
  2024-09-08 11:39     ` Andreas Schwab
  0 siblings, 2 replies; 30+ messages in thread
From: Ship Mints @ 2024-09-08 10:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73098

[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]

Yessir. I was talking about users' likely expectations for type coercion.
There are cases in elisp where numeric type coercion is the default,
e.g., (= 2.0 2) is t. I expected it to be so here, too.

If you feel this is moot, then so be it.

On Sun, Sep 8, 2024 at 2:07 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Ship Mints <shipmints@gmail.com>
> > Date: Sat, 7 Sep 2024 09:14:54 -0400
> >
> > This one bit me yesterday on Emacs 29.3 as I was revising my init file
> (for the thousandth time this week).
> >
> > As setopt becomes more widely recommended, people will likely encounter
> situations like the below where they
> > expect constant numeric types to be coerced.
> >
> > (defcustom temp-float "Float"
> >   "Float type."
> >   :type 'float)
> >
> > (setopt temp-float 2.0) ; works
> > (setopt temp-float 2) ; Warning (emacs): Value '2' does not match type
> float
>
> If you are going to allow integer values, shouldn't :type be 'number,
> not 'float?  The documentation of 'float says:
>
>   ‘float’
>        The value must be floating point.
>
> "Must be floating point."  The value 2 isn't.
>

[-- Attachment #2: Type: text/html, Size: 1832 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-08 10:59   ` Ship Mints
@ 2024-09-08 11:08     ` Eli Zaretskii
  2024-09-08 11:15       ` Ship Mints
  2024-09-08 11:39     ` Andreas Schwab
  1 sibling, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-08 11:08 UTC (permalink / raw)
  To: Ship Mints; +Cc: 73098

> From: Ship Mints <shipmints@gmail.com>
> Date: Sun, 8 Sep 2024 06:59:31 -0400
> Cc: 73098@debbugs.gnu.org
> 
> Yessir. I was talking about users' likely expectations for type coercion. There are cases in elisp where numeric
> type coercion is the default, e.g., (= 2.0 2) is t. I expected it to be so here, too.
> 
> If you feel this is moot, then so be it.

Let's see if there are other opinions.

But basically, you'd like 'float to be an alias for 'number, right?





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-08 11:08     ` Eli Zaretskii
@ 2024-09-08 11:15       ` Ship Mints
  2024-09-09 15:11         ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 30+ messages in thread
From: Ship Mints @ 2024-09-08 11:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73098

[-- Attachment #1: Type: text/plain, Size: 916 bytes --]

I'm suggesting that there will be noise from people who convert from a
working (setq some-package-option 2) to (setopt some-package-option 2).
This is not a request to change the elisp type system, it is a request to
consider if setopt's / customize internals should be relaxed to the
equivalent of #'= for these simple cases.

On Sun, Sep 8, 2024 at 7:09 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Ship Mints <shipmints@gmail.com>
> > Date: Sun, 8 Sep 2024 06:59:31 -0400
> > Cc: 73098@debbugs.gnu.org
> >
> > Yessir. I was talking about users' likely expectations for type
> coercion. There are cases in elisp where numeric
> > type coercion is the default, e.g., (= 2.0 2) is t. I expected it to be
> so here, too.
> >
> > If you feel this is moot, then so be it.
>
> Let's see if there are other opinions.
>
> But basically, you'd like 'float to be an alias for 'number, right?
>

[-- Attachment #2: Type: text/html, Size: 1441 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-08 10:59   ` Ship Mints
  2024-09-08 11:08     ` Eli Zaretskii
@ 2024-09-08 11:39     ` Andreas Schwab
  2024-09-08 12:28       ` Ship Mints
  1 sibling, 1 reply; 30+ messages in thread
From: Andreas Schwab @ 2024-09-08 11:39 UTC (permalink / raw)
  To: Ship Mints; +Cc: Eli Zaretskii, 73098

On Sep 08 2024, Ship Mints wrote:

> There are cases in elisp where numeric type coercion is the default,
> e.g., (= 2.0 2) is t. I expected it to be so here, too.

That's because the function accepts a number, not a float.  If you want
to accept any kind of number, just say so.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-08 11:39     ` Andreas Schwab
@ 2024-09-08 12:28       ` Ship Mints
  0 siblings, 0 replies; 30+ messages in thread
From: Ship Mints @ 2024-09-08 12:28 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Eli Zaretskii, 73098

[-- Attachment #1: Type: text/plain, Size: 1209 bytes --]

100% correct...when one controls the code base in question. For the many
packages out there with strict types in their defcustom definitions and
with many/most users using setq over customize, there will be lots of
surprise for simple cases like this when they try setopt. Perhaps more
vocal advisories for package authors to provide updates (though many seem
fallow), and for users might be sufficient without resorting to monkey
patching. Most, I suspect, will just revert to setq and ignore custom type
validations. Most don't even check for the presence of setters and I've
assisted many in my circles with their resulting heisenbugs.

On Sun, Sep 8, 2024 at 7:39 AM Andreas Schwab <schwab@linux-m68k.org> wrote:

> On Sep 08 2024, Ship Mints wrote:
>
> > There are cases in elisp where numeric type coercion is the default,
> > e.g., (= 2.0 2) is t. I expected it to be so here, too.
>
> That's because the function accepts a number, not a float.  If you want
> to accept any kind of number, just say so.
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."
>

[-- Attachment #2: Type: text/html, Size: 1656 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-08 11:15       ` Ship Mints
@ 2024-09-09 15:11         ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-09 15:28           ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-09 15:11 UTC (permalink / raw)
  To: Ship Mints; +Cc: Eli Zaretskii, 73098

Ship Mints <shipmints@gmail.com> writes:

> I'm suggesting that there will be noise from people who convert from a
> working (setq some-package-option 2) to (setopt some-package-option
> 2). This is not a request to change the elisp type system, it is a
> request to consider if setopt's / customize internals should be
> relaxed to the equivalent of #'= for these simple cases.

How about adding an option letting the user disable the type checking of
some options?


Michael.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 15:11         ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-09 15:28           ` Eli Zaretskii
  2024-09-09 15:35             ` Ship Mints
                               ` (2 more replies)
  0 siblings, 3 replies; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-09 15:28 UTC (permalink / raw)
  To: Michael Heerdegen, Stefan Monnier; +Cc: 73098, shipmints

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Cc: Eli Zaretskii <eliz@gnu.org>,  73098@debbugs.gnu.org
> Date: Mon, 09 Sep 2024 17:11:40 +0200
> 
> Ship Mints <shipmints@gmail.com> writes:
> 
> > I'm suggesting that there will be noise from people who convert from a
> > working (setq some-package-option 2) to (setopt some-package-option
> > 2). This is not a request to change the elisp type system, it is a
> > request to consider if setopt's / customize internals should be
> > relaxed to the equivalent of #'= for these simple cases.
> 
> How about adding an option letting the user disable the type checking of
> some options?

Like what?  Would we accept, for example, a string where the type is
'symbol'?  Or any value where type is 'boolean'?

And I'm also not sure we want this: presumably, if the defcustom's
author specified a type, they meant it, no?

Which is why I asked for opinions (but for now got only yours).

Stefan, WDYT?





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 15:28           ` Eli Zaretskii
@ 2024-09-09 15:35             ` Ship Mints
  2024-09-09 16:40               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-09 16:38             ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-09 22:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2 siblings, 1 reply; 30+ messages in thread
From: Ship Mints @ 2024-09-09 15:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Michael Heerdegen, 73098, Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 1424 bytes --]

Perhaps an alternative macro `setopt-relaxed"? Documentation should suggest
contacting package authors to request improvements (it's a very slow
process to get misspecified packages updated and not all authors mean what
they say when they themselves don't use the customize system--this group
must know this all too well).

On Mon, Sep 9, 2024 at 11:28 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Michael Heerdegen <michael_heerdegen@web.de>
> > Cc: Eli Zaretskii <eliz@gnu.org>,  73098@debbugs.gnu.org
> > Date: Mon, 09 Sep 2024 17:11:40 +0200
> >
> > Ship Mints <shipmints@gmail.com> writes:
> >
> > > I'm suggesting that there will be noise from people who convert from a
> > > working (setq some-package-option 2) to (setopt some-package-option
> > > 2). This is not a request to change the elisp type system, it is a
> > > request to consider if setopt's / customize internals should be
> > > relaxed to the equivalent of #'= for these simple cases.
> >
> > How about adding an option letting the user disable the type checking of
> > some options?
>
> Like what?  Would we accept, for example, a string where the type is
> 'symbol'?  Or any value where type is 'boolean'?
>
> And I'm also not sure we want this: presumably, if the defcustom's
> author specified a type, they meant it, no?
>
> Which is why I asked for opinions (but for now got only yours).
>
> Stefan, WDYT?
>

[-- Attachment #2: Type: text/html, Size: 2191 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 15:28           ` Eli Zaretskii
  2024-09-09 15:35             ` Ship Mints
@ 2024-09-09 16:38             ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-09 17:37               ` Eli Zaretskii
  2024-09-09 22:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2 siblings, 1 reply; 30+ messages in thread
From: Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-09 16:38 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73098, Stefan Monnier, shipmints

Eli Zaretskii <eliz@gnu.org> writes:

> > How about adding an option letting the user disable the type checking of
> > some options?
>
> Like what?  Would we accept, for example, a string where the type is
> 'symbol'?  Or any value where type is 'boolean'?

The new option would have as value a list of option names.  The user
could then add those options with incorrect type specs.  And for those
specified options Emacs would skip type checking entirely.

I _don't_ think melting types in either way would be a good idea.


Michael.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 15:35             ` Ship Mints
@ 2024-09-09 16:40               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 30+ messages in thread
From: Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-09 16:40 UTC (permalink / raw)
  To: Ship Mints; +Cc: Eli Zaretskii, 73098, Stefan Monnier

Ship Mints <shipmints@gmail.com> writes:

> Perhaps an alternative macro `setopt-relaxed"? Documentation should
> suggest contacting package authors to request improvements (it's a
> very slow process to get misspecified packages updated and not all
> authors mean what they say when they themselves don't use the
> customize system--this group must know this all too well).

Dunno 'bout the name, but the idea sounds ok to me.


Michael.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 16:38             ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-09 17:37               ` Eli Zaretskii
  2024-09-09 17:46                 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-09 17:37 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 73098, monnier, shipmints

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>,  shipmints@gmail.com,
>   73098@debbugs.gnu.org
> Date: Mon, 09 Sep 2024 18:38:43 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > > How about adding an option letting the user disable the type checking of
> > > some options?
> >
> > Like what?  Would we accept, for example, a string where the type is
> > 'symbol'?  Or any value where type is 'boolean'?
> 
> The new option would have as value a list of option names.  The user
> could then add those options with incorrect type specs.  And for those
> specified options Emacs would skip type checking entirely.

Thanks, but this sounds like overkill to me.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 17:37               ` Eli Zaretskii
@ 2024-09-09 17:46                 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-09 19:02                   ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-09 17:46 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73098, monnier, shipmints

Eli Zaretskii <eliz@gnu.org> writes:

> Thanks, but this sounds like overkill to me.

Hmm... maybe.  And the idea of an extra macro?


Michael.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 17:46                 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-09 19:02                   ` Eli Zaretskii
  0 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-09 19:02 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 73098, monnier, shipmints

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Cc: monnier@iro.umontreal.ca,  shipmints@gmail.com,  73098@debbugs.gnu.org
> Date: Mon, 09 Sep 2024 19:46:56 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Thanks, but this sounds like overkill to me.
> 
> Hmm... maybe.  And the idea of an extra macro?

Likewise.

I think we should make up our minds: either we enforce :type in setopt
or we don't.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 15:28           ` Eli Zaretskii
  2024-09-09 15:35             ` Ship Mints
  2024-09-09 16:38             ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-09 22:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-10  8:22               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
                                 ` (2 more replies)
  2 siblings, 3 replies; 30+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-09 22:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Michael Heerdegen, 73098, shipmints

> Like what?  Would we accept, for example, a string where the type is
> 'symbol'?  Or any value where type is 'boolean'?
>
> And I'm also not sure we want this: presumably, if the defcustom's
> author specified a type, they meant it, no?

I tend to agree.  If the type doesn't accept the value, you can use
something lower-level than `setopt`, while you argue with the maintainer
to try and get them to change their type.

IMO, the whole point of `setopt` is to check the value against the type.


        Stefan






^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 22:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-10  8:22               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-10 11:58                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-10 11:36               ` Eli Zaretskii
  2024-09-11 22:53               ` Stefan Kangas
  2 siblings, 1 reply; 30+ messages in thread
From: Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-10  8:22 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Eli Zaretskii, 73098, shipmints

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> I tend to agree.  If the type doesn't accept the value, you can use
> something lower-level than `setopt` [...]

What would that be in case the option has a custom setter function?


Michael.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 22:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-10  8:22               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-10 11:36               ` Eli Zaretskii
  2024-09-11 22:53               ` Stefan Kangas
  2 siblings, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-10 11:36 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: michael_heerdegen, 73098, shipmints

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Cc: Michael Heerdegen <michael_heerdegen@web.de>,  shipmints@gmail.com,
>   73098@debbugs.gnu.org
> Date: Mon, 09 Sep 2024 18:41:46 -0400
> 
> IMO, the whole point of `setopt` is to check the value against the type.

I agree, but some users expect setopt to be a variant of setq,
especially since we advertise such use of setopt for modifying user
options.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-10  8:22               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-10 11:58                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 30+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-10 11:58 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Eli Zaretskii, 73098, shipmints

>> I tend to agree.  If the type doesn't accept the value, you can use
>> something lower-level than `setopt` [...]
> What would that be in case the option has a custom setter function?

AFAIK people used `setq` before `setopt`.  For vars that come with
setter functions, this usually doesn't work quite the same, but in 99%
it's good enough if the `setq` is performed early during startup.

You can also

    (put '<SYM> 'custom-type t)

if you want to disable type-checking for a specific variable.


        Stefan






^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-09 22:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-10  8:22               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-10 11:36               ` Eli Zaretskii
@ 2024-09-11 22:53               ` Stefan Kangas
  2024-09-13 15:11                 ` Ship Mints
  2 siblings, 1 reply; 30+ messages in thread
From: Stefan Kangas @ 2024-09-11 22:53 UTC (permalink / raw)
  To: Stefan Monnier, Eli Zaretskii; +Cc: Michael Heerdegen, 73098, shipmints

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> I tend to agree.  If the type doesn't accept the value, you can use
> something lower-level than `setopt`, while you argue with the maintainer
> to try and get them to change their type.
>
> IMO, the whole point of `setopt` is to check the value against the type.

+1





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-11 22:53               ` Stefan Kangas
@ 2024-09-13 15:11                 ` Ship Mints
  2024-09-13 15:28                   ` Eli Zaretskii
  2024-09-13 19:09                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 2 replies; 30+ messages in thread
From: Ship Mints @ 2024-09-13 15:11 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Michael Heerdegen, Eli Zaretskii, 73098, Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 1807 bytes --]

Happy for the thoughtful feedback.

Perhaps, some expanded advice in the docstring for setopt?

"Set VARIABLE/VALUE pairs with enforced types, and return the final VALUE.

This is like setq, but is meant for user options instead of
plain variables.  This means that setopt will execute any
custom-set form associated with VARIABLE, and strictly ensure
that VALUE is of the type declared by the user option.

Example: If the user option is declared to accept a `float',
set the option to 2.0, not to 2 which is considered an `integer'.

Note: Many user options accept more complex types than a scalar
float and that may pose a challenge to address when setting them
in elisp using setopt.

If you encounter a discrepancy that cannot be addressed by amending
the type specified by a setopt call, and you can deem the desired
type compatible nonetheless, use setq. If the user option has an
associated \"setter\" you may invoke it manually using ???"

Then there's the twist that some options force content checks, not just
type checks. An example of a user option that is intended to be overridden
with custom entries is tab-bar-format. The setopt type checker will barf on
entries not strictly in the tab-bar-format pre-populated list despite the
type being a normal hook.


On Wed, Sep 11, 2024 at 6:53 PM Stefan Kangas <stefankangas@gmail.com>
wrote:

> Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" <bug-gnu-emacs@gnu.org> writes:
>
> > I tend to agree.  If the type doesn't accept the value, you can use
> > something lower-level than `setopt`, while you argue with the maintainer
> > to try and get them to change their type.
> >
> > IMO, the whole point of `setopt` is to check the value against the type.
>
> +1
>

[-- Attachment #2: Type: text/html, Size: 3551 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 15:11                 ` Ship Mints
@ 2024-09-13 15:28                   ` Eli Zaretskii
  2024-09-13 17:14                     ` Ship Mints
  2024-09-13 19:09                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  1 sibling, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-13 15:28 UTC (permalink / raw)
  To: Ship Mints; +Cc: michael_heerdegen, 73098, stefankangas, monnier

> From: Ship Mints <shipmints@gmail.com>
> Date: Fri, 13 Sep 2024 11:11:18 -0400
> Cc: Stefan Monnier <monnier@iro.umontreal.ca>, Eli Zaretskii <eliz@gnu.org>, 
> 	Michael Heerdegen <michael_heerdegen@web.de>, 73098@debbugs.gnu.org
> 
> Perhaps, some expanded advice in the docstring for setopt?
> 
> "Set VARIABLE/VALUE pairs with enforced types, and return the final VALUE.

"Enforce" is inaccurate, since a value that doesn't match :type just
emits a warning (which can be shut up by the users, if they want), it
doesn't signal an error.  And the variable is assigned the value event
if the type doesn't match.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 15:28                   ` Eli Zaretskii
@ 2024-09-13 17:14                     ` Ship Mints
  2024-09-13 18:27                       ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-14  9:35                       ` Eli Zaretskii
  0 siblings, 2 replies; 30+ messages in thread
From: Ship Mints @ 2024-09-13 17:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: michael_heerdegen, 73098, stefankangas, monnier

[-- Attachment #1: Type: text/plain, Size: 1291 bytes --]

Revised language:

"Set VARIABLE/VALUE pairs with type warnings, and return the final VALUE.

This is like setq, but is meant for user options instead of
plain variables.  This means that setopt will execute any
custom-set form associated with VARIABLE, and will emit a
warning if VALUE is not of the type expected by the user option.

Example: If the user option is declared to accept a `float',
set the option to 2.0 rather than 2, which is considered an `integer'.

Despite the warning, the user option will still be set to VALUE."

On Fri, Sep 13, 2024 at 11:28 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Ship Mints <shipmints@gmail.com>
> > Date: Fri, 13 Sep 2024 11:11:18 -0400
> > Cc: Stefan Monnier <monnier@iro.umontreal.ca>, Eli Zaretskii <
> eliz@gnu.org>,
> >       Michael Heerdegen <michael_heerdegen@web.de>,
> 73098@debbugs.gnu.org
> >
> > Perhaps, some expanded advice in the docstring for setopt?
> >
> > "Set VARIABLE/VALUE pairs with enforced types, and return the final
> VALUE.
>
> "Enforce" is inaccurate, since a value that doesn't match :type just
> emits a warning (which can be shut up by the users, if they want), it
> doesn't signal an error.  And the variable is assigned the value event
> if the type doesn't match.
>

[-- Attachment #2: Type: text/html, Size: 2683 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 17:14                     ` Ship Mints
@ 2024-09-13 18:27                       ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-14  9:35                       ` Eli Zaretskii
  1 sibling, 0 replies; 30+ messages in thread
From: Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-13 18:27 UTC (permalink / raw)
  To: Ship Mints, Eli Zaretskii
  Cc: michael_heerdegen@web.de, 73098@debbugs.gnu.org,
	stefankangas@gmail.com, monnier@iro.umontreal.ca

> setopt will execute any custom-set form
                          ^^^^^^^^^^^^^^^
> associated with VARIABLE

1. "custom-set form" isn't mentioned, let alone
   defined, in the Elisp manual.  Should this
   say "any defcustom :set function" instead?

2. What about what I suppose you would call a
   "custom-init form", in other words, what the
   Elisp manual calls ":initialize function"? 



^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 15:11                 ` Ship Mints
  2024-09-13 15:28                   ` Eli Zaretskii
@ 2024-09-13 19:09                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-09-13 19:26                     ` Ship Mints
  1 sibling, 1 reply; 30+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-09-13 19:09 UTC (permalink / raw)
  To: Ship Mints; +Cc: Michael Heerdegen, Eli Zaretskii, 73098, Stefan Kangas

> If you encounter a discrepancy that cannot be addressed by amending
> the type specified by a setopt call, and you can deem the desired
> type compatible nonetheless, use setq. If the user option has an
> associated \"setter\" you may invoke it manually using ???"

You're here trying to describe workarounds to use in case of bugs
(either the value you set is wrong, or the type (or type-checker) is
wrong).  We usually don't do that in docstrings.


        Stefan






^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 19:09                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-13 19:26                     ` Ship Mints
  2024-09-13 19:38                       ` Ship Mints
  0 siblings, 1 reply; 30+ messages in thread
From: Ship Mints @ 2024-09-13 19:26 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Michael Heerdegen, Eli Zaretskii, 73098, Stefan Kangas

[-- Attachment #1: Type: text/plain, Size: 692 bytes --]

It was removed in a later proposed edit. I read the setopt code more deeply
and ran some tests.

On Fri, Sep 13, 2024 at 3:09 PM Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > If you encounter a discrepancy that cannot be addressed by amending
> > the type specified by a setopt call, and you can deem the desired
> > type compatible nonetheless, use setq. If the user option has an
> > associated \"setter\" you may invoke it manually using ???"
>
> You're here trying to describe workarounds to use in case of bugs
> (either the value you set is wrong, or the type (or type-checker) is
> wrong).  We usually don't do that in docstrings.
>
>
>         Stefan
>
>

[-- Attachment #2: Type: text/html, Size: 1098 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 19:26                     ` Ship Mints
@ 2024-09-13 19:38                       ` Ship Mints
  2024-09-14  6:15                         ` Eli Zaretskii
  0 siblings, 1 reply; 30+ messages in thread
From: Ship Mints @ 2024-09-13 19:38 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Michael Heerdegen, Eli Zaretskii, 73098, Stefan Kangas

[-- Attachment #1: Type: text/plain, Size: 1287 bytes --]

The warning messages can be misleading. e.g., when trying to set
tab-bar-format-tabs-groups to include a simple lambda, it complains about
the wrong thing. It does match the hook type, but does not match the
hard-coded list of options.

   (setopt tab-bar-format
           `(
             tab-bar-format-tabs-groups
             (lambda () " ") ; tab-bar-separator
    ))

 ■  Warning (emacs): Value '(nil tab-bar-format-tabs-groups (lambda nil "
"))' does not match type hook

On Fri, Sep 13, 2024 at 3:26 PM Ship Mints <shipmints@gmail.com> wrote:

> It was removed in a later proposed edit. I read the setopt code more
> deeply and ran some tests.
>
> On Fri, Sep 13, 2024 at 3:09 PM Stefan Monnier <monnier@iro.umontreal.ca>
> wrote:
>
>> > If you encounter a discrepancy that cannot be addressed by amending
>> > the type specified by a setopt call, and you can deem the desired
>> > type compatible nonetheless, use setq. If the user option has an
>> > associated \"setter\" you may invoke it manually using ???"
>>
>> You're here trying to describe workarounds to use in case of bugs
>> (either the value you set is wrong, or the type (or type-checker) is
>> wrong).  We usually don't do that in docstrings.
>>
>>
>>         Stefan
>>
>>

[-- Attachment #2: Type: text/html, Size: 2401 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 19:38                       ` Ship Mints
@ 2024-09-14  6:15                         ` Eli Zaretskii
  2024-09-14 12:33                           ` Ship Mints
  0 siblings, 1 reply; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-14  6:15 UTC (permalink / raw)
  To: Ship Mints; +Cc: michael_heerdegen, 73098, monnier, stefankangas

> From: Ship Mints <shipmints@gmail.com>
> Date: Fri, 13 Sep 2024 15:38:28 -0400
> Cc: Stefan Kangas <stefankangas@gmail.com>, Eli Zaretskii <eliz@gnu.org>, 
> 	Michael Heerdegen <michael_heerdegen@web.de>, 73098@debbugs.gnu.org
> 
> The warning messages can be misleading. e.g., when trying to set tab-bar-format-tabs-groups to include a
> simple lambda, it complains about the wrong thing. It does match the hook type, but does not match the
> hard-coded list of options.
> 
>    (setopt tab-bar-format
>            `(
>              tab-bar-format-tabs-groups
>              (lambda () " ") ; tab-bar-separator
>     ))
> 
>  ■  Warning (emacs): Value '(nil tab-bar-format-tabs-groups (lambda nil " "))' does not match type hook

I don't get a warning when I evaluate the above.  Is this in "emacs -Q"?





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-13 17:14                     ` Ship Mints
  2024-09-13 18:27                       ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-09-14  9:35                       ` Eli Zaretskii
  1 sibling, 0 replies; 30+ messages in thread
From: Eli Zaretskii @ 2024-09-14  9:35 UTC (permalink / raw)
  To: Ship Mints; +Cc: michael_heerdegen, 73098-done, stefankangas, monnier

> From: Ship Mints <shipmints@gmail.com>
> Date: Fri, 13 Sep 2024 13:14:59 -0400
> Cc: stefankangas@gmail.com, monnier@iro.umontreal.ca, michael_heerdegen@web.de, 
> 	73098@debbugs.gnu.org
> 
> Revised language:
> 
> "Set VARIABLE/VALUE pairs with type warnings, and return the final VALUE.
> 
> This is like setq, but is meant for user options instead of
> plain variables.  This means that setopt will execute any
> custom-set form associated with VARIABLE, and will emit a
> warning if VALUE is not of the type expected by the user option.
> 
> Example: If the user option is declared to accept a `float', 
> set the option to 2.0 rather than 2, which is considered an `integer'.
> 
> Despite the warning, the user option will still be set to VALUE."

Thanks.  Since there seems to be a consensus that 'setopt' should
continue emitting the warning, I added to the doc string a note about
the warning (on the emacs-30 branch), and I'm now closing this bug.





^ permalink raw reply	[flat|nested] 30+ messages in thread

* bug#73098: setopt float warning unexpected
  2024-09-14  6:15                         ` Eli Zaretskii
@ 2024-09-14 12:33                           ` Ship Mints
  0 siblings, 0 replies; 30+ messages in thread
From: Ship Mints @ 2024-09-14 12:33 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: michael_heerdegen, 73098, monnier, stefankangas

[-- Attachment #1: Type: text/plain, Size: 1148 bytes --]

I didn't try -Q assuming this behavior would be unaffected. I'll try to
keep this simple case in mind for future reproducers and go native when
practical. Thank you for the docstring edits.

On Sat, Sep 14, 2024 at 2:15 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Ship Mints <shipmints@gmail.com>
> > Date: Fri, 13 Sep 2024 15:38:28 -0400
> > Cc: Stefan Kangas <stefankangas@gmail.com>, Eli Zaretskii <eliz@gnu.org>,
>
> >       Michael Heerdegen <michael_heerdegen@web.de>,
> 73098@debbugs.gnu.org
> >
> > The warning messages can be misleading. e.g., when trying to set
> tab-bar-format-tabs-groups to include a
> > simple lambda, it complains about the wrong thing. It does match the
> hook type, but does not match the
> > hard-coded list of options.
> >
> >    (setopt tab-bar-format
> >            `(
> >              tab-bar-format-tabs-groups
> >              (lambda () " ") ; tab-bar-separator
> >     ))
> >
> >  ■  Warning (emacs): Value '(nil tab-bar-format-tabs-groups (lambda nil
> " "))' does not match type hook
>
> I don't get a warning when I evaluate the above.  Is this in "emacs -Q"?
>

[-- Attachment #2: Type: text/html, Size: 1945 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2024-09-14 12:33 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-07 13:14 bug#73098: setopt float warning unexpected Ship Mints
2024-09-08  6:06 ` Eli Zaretskii
2024-09-08 10:59   ` Ship Mints
2024-09-08 11:08     ` Eli Zaretskii
2024-09-08 11:15       ` Ship Mints
2024-09-09 15:11         ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 15:28           ` Eli Zaretskii
2024-09-09 15:35             ` Ship Mints
2024-09-09 16:40               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 16:38             ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 17:37               ` Eli Zaretskii
2024-09-09 17:46                 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-09 19:02                   ` Eli Zaretskii
2024-09-09 22:41             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-10  8:22               ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-10 11:58                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-10 11:36               ` Eli Zaretskii
2024-09-11 22:53               ` Stefan Kangas
2024-09-13 15:11                 ` Ship Mints
2024-09-13 15:28                   ` Eli Zaretskii
2024-09-13 17:14                     ` Ship Mints
2024-09-13 18:27                       ` Drew Adams via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-14  9:35                       ` Eli Zaretskii
2024-09-13 19:09                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-09-13 19:26                     ` Ship Mints
2024-09-13 19:38                       ` Ship Mints
2024-09-14  6:15                         ` Eli Zaretskii
2024-09-14 12:33                           ` Ship Mints
2024-09-08 11:39     ` Andreas Schwab
2024-09-08 12:28       ` Ship Mints

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.