GNU bug report logs - #56400
Make setopt warn on type mismatch

Previous Next

Package: emacs;

Reported by: Stefan Kangas <stefan <at> marxist.se>

Date: Tue, 5 Jul 2022 15:33:02 UTC

Severity: wishlist

Tags: moreinfo

Fixed in version 29.1

Done: Stefan Kangas <stefan <at> marxist.se>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 56400 in the body.
You can then email your comments to 56400 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#56400; Package emacs. (Tue, 05 Jul 2022 15:33:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Kangas <stefan <at> marxist.se>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 05 Jul 2022 15:33:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: bug-gnu-emacs <at> gnu.org
Subject: Make setopt warn on type mismatch
Date: Tue, 5 Jul 2022 08:32:29 -0700
Severity: wishlist

Why not make `setopt' warn in case there is a type mismatch?
For example, in:

    (setopt tetris-buffer-width "hello")

But the type of `tetris-buffer-width' is natnum.

I think this would save users from shooting themselves in the foot.
If they are sure they want to do that, they can use `setq' or
`customize-set-variable' directly.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56400; Package emacs. (Tue, 05 Jul 2022 16:58:01 GMT) Full text and rfc822 format available.

Message #8 received at 56400 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 56400 <at> debbugs.gnu.org
Subject: Re: bug#56400: Make setopt warn on type mismatch
Date: Tue, 05 Jul 2022 18:57:17 +0200
Stefan Kangas <stefan <at> marxist.se> writes:

> Why not make `setopt' warn in case there is a type mismatch?
> For example, in:
>
>     (setopt tetris-buffer-width "hello")
>
> But the type of `tetris-buffer-width' is natnum.

It should throw an error already:

;;;###autoload
(defun setopt--set (variable value)
  (custom-load-symbol variable)
  ;; Check that the type is correct.
  (when-let ((type (get variable 'custom-type)))
    (unless (widget-apply (widget-convert type) :match value)
      (user-error "Value `%S' does not match type %s" value type)))

Did you mean a byte compilation warning?  I don't really think that
people will be using setopt much in code, just in .emacs, so I'm not
sure that'd give us much.

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




Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 05 Jul 2022 16:58:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56400; Package emacs. (Tue, 05 Jul 2022 17:09:02 GMT) Full text and rfc822 format available.

Message #13 received at 56400 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 56400 <at> debbugs.gnu.org
Subject: Re: bug#56400: Make setopt warn on type mismatch
Date: Tue, 5 Jul 2022 19:08:24 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Stefan Kangas <stefan <at> marxist.se> writes:
>
> > Why not make `setopt' warn in case there is a type mismatch?
> > For example, in:
> >
> >     (setopt tetris-buffer-width "hello")
> >
> > But the type of `tetris-buffer-width' is natnum.
>
> It should throw an error already:

Aha, I guess it doesn't throw an error if `tetris' isn't loaded
already, as it has no way of knowing the type yet.  IOW, in emacs -Q,
I need to say this to get an error:

(progn
  (require 'tetris)
  (setopt tetris-buffer-width "hello"))

That's pretty good, but I wonder if we could do better.  I expect that
users will often set settings from libraries that aren't yet loaded.
For example, how about warning upon loading the library if the
variable is set to an incompatible value?  Or something.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56400; Package emacs. (Tue, 05 Jul 2022 17:34:02 GMT) Full text and rfc822 format available.

Message #16 received at 56400 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 56400 <at> debbugs.gnu.org
Subject: Re: bug#56400: Make setopt warn on type mismatch
Date: Tue, 05 Jul 2022 19:32:53 +0200
Stefan Kangas <stefan <at> marxist.se> writes:

> Aha, I guess it doesn't throw an error if `tetris' isn't loaded
> already, as it has no way of knowing the type yet.  IOW, in emacs -Q,
> I need to say this to get an error:
>
> (progn
>   (require 'tetris)
>   (setopt tetris-buffer-width "hello"))

Yup.

> That's pretty good, but I wonder if we could do better.  I expect that
> users will often set settings from libraries that aren't yet loaded.
> For example, how about warning upon loading the library if the
> variable is set to an incompatible value?  Or something.

Hm...  yes, that should certainly be possible.  I guess the check would
go in...  `custom-declare-variable'?  Yeah, almost.

Now fixed in Emacs 29.

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




bug marked as fixed in version 29.1, send any further explanations to 56400 <at> debbugs.gnu.org and Stefan Kangas <stefan <at> marxist.se> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 05 Jul 2022 17:34:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56400; Package emacs. (Tue, 05 Jul 2022 17:44:01 GMT) Full text and rfc822 format available.

Message #21 received at 56400 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefan <at> marxist.se>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: 56400 <at> debbugs.gnu.org
Subject: Re: bug#56400: Make setopt warn on type mismatch
Date: Tue, 5 Jul 2022 19:42:58 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> writes:

> Now fixed in Emacs 29.

Thanks!  Should this change be in NEWS?  I guess it affects both
`setq' and `setopt'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56400; Package emacs. (Tue, 05 Jul 2022 18:08:01 GMT) Full text and rfc822 format available.

Message #24 received at 56400 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 56400 <at> debbugs.gnu.org
Subject: Re: bug#56400: Make setopt warn on type mismatch
Date: Tue, 05 Jul 2022 20:07:41 +0200
Stefan Kangas <stefan <at> marxist.se> writes:

> Thanks!  Should this change be in NEWS?  I guess it affects both
> `setq' and `setopt'.

No, just setopt -- it only gives the warning if the variable has been
set with setopt.

I didn't think it was NEWS-worthy, seeing as `setopt' is new in Emacs
29, and this is just part of how it works (now).

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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#56400; Package emacs. (Wed, 06 Jul 2022 08:20:03 GMT) Full text and rfc822 format available.

Message #27 received at 56400 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Stefan Kangas <stefan <at> marxist.se>
Cc: 56400 <at> debbugs.gnu.org
Subject: Re: bug#56400: Make setopt warn on type mismatch
Date: Tue, 05 Jul 2022 21:51:01 +0300
> Why not make `setopt' warn in case there is a type mismatch?
> For example, in:
>
>     (setopt tetris-buffer-width "hello")
>
> But the type of `tetris-buffer-width' is natnum.
>
> I think this would save users from shooting themselves in the foot.
> If they are sure they want to do that, they can use `setq' or
> `customize-set-variable' directly.

This is exactly what `set-variable' does.




bug marked as fixed in version 29.1, send any further explanations to 56400 <at> debbugs.gnu.org and Stefan Kangas <stefan <at> marxist.se> Request was from Stefan Kangas <stefan <at> marxist.se> to control <at> debbugs.gnu.org. (Wed, 06 Jul 2022 10:44:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 03 Aug 2022 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 358 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.