unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#56400: Make setopt warn on type mismatch
@ 2022-07-05 15:32 Stefan Kangas
  2022-07-05 16:57 ` Lars Ingebrigtsen
  2022-07-05 18:51 ` Juri Linkov
  0 siblings, 2 replies; 7+ messages in thread
From: Stefan Kangas @ 2022-07-05 15:32 UTC (permalink / raw)
  To: 56400

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.





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

* bug#56400: Make setopt warn on type mismatch
  2022-07-05 15:32 bug#56400: Make setopt warn on type mismatch Stefan Kangas
@ 2022-07-05 16:57 ` Lars Ingebrigtsen
  2022-07-05 17:08   ` Stefan Kangas
  2022-07-05 18:51 ` Juri Linkov
  1 sibling, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-05 16:57 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 56400

Stefan Kangas <stefan@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





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

* bug#56400: Make setopt warn on type mismatch
  2022-07-05 16:57 ` Lars Ingebrigtsen
@ 2022-07-05 17:08   ` Stefan Kangas
  2022-07-05 17:32     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Kangas @ 2022-07-05 17:08 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 56400

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Stefan Kangas <stefan@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.





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

* bug#56400: Make setopt warn on type mismatch
  2022-07-05 17:08   ` Stefan Kangas
@ 2022-07-05 17:32     ` Lars Ingebrigtsen
  2022-07-05 17:42       ` Stefan Kangas
  0 siblings, 1 reply; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-05 17:32 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 56400

Stefan Kangas <stefan@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





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

* bug#56400: Make setopt warn on type mismatch
  2022-07-05 17:32     ` Lars Ingebrigtsen
@ 2022-07-05 17:42       ` Stefan Kangas
  2022-07-05 18:07         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 7+ messages in thread
From: Stefan Kangas @ 2022-07-05 17:42 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 56400

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Now fixed in Emacs 29.

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





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

* bug#56400: Make setopt warn on type mismatch
  2022-07-05 17:42       ` Stefan Kangas
@ 2022-07-05 18:07         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-07-05 18:07 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 56400

Stefan Kangas <stefan@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





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

* bug#56400: Make setopt warn on type mismatch
  2022-07-05 15:32 bug#56400: Make setopt warn on type mismatch Stefan Kangas
  2022-07-05 16:57 ` Lars Ingebrigtsen
@ 2022-07-05 18:51 ` Juri Linkov
  1 sibling, 0 replies; 7+ messages in thread
From: Juri Linkov @ 2022-07-05 18:51 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 56400

> 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.





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

end of thread, other threads:[~2022-07-05 18:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-05 15:32 bug#56400: Make setopt warn on type mismatch Stefan Kangas
2022-07-05 16:57 ` Lars Ingebrigtsen
2022-07-05 17:08   ` Stefan Kangas
2022-07-05 17:32     ` Lars Ingebrigtsen
2022-07-05 17:42       ` Stefan Kangas
2022-07-05 18:07         ` Lars Ingebrigtsen
2022-07-05 18:51 ` Juri Linkov

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).