Subject: bug#65411: 29.1; setopt of xref-after-jump-hook gives warning

From: Eli Zaretskii <[email-masked]>
Date: Mon, 21 Aug 2023 15:01:07 +0300

> From: Howard Melman <[email-masked]>
> Date: Sun, 20 Aug 2023 20:21:39 -0400
> Cc: [email-masked]
> 
> >> So why does it fail using setopt?
> > 
> > Because until xref is loaded, Emacs doesn't know that
> > 'xref-pulse-momentarily' is a symbol of function, whereas the
> > defcustom's type is 'hook', which stands for "a list of functions".
> 
> Well, that must be correct because doing this also worked fine:
> 
>   (declare-function xref-pulse-momentarily "xref" ())
>   (setopt xref-after-jump-hook '(reposition-window xref-pulse-momentarily))
> 
> So I guess setopt defers the type check?

No, it just verifies that the symbol's function slot is valid.

> I get the error when the hook is run (at which time xref is loaded
> so I'm still confused about that).

declare-function doesn't provider an actual function definition, it
just provides a declaration.  IOW, you lie to Emacs, and Emacs bites
you when it can ;-)

> I'm familiar with reading the lisp code but the innards of custom and
> the c code are a bit beyond me.  Is it the custom-check-value property
> in setopt--set?

Yes.

> If I'm supposed to resolve this warning on my own, then a comment
> in setopt--set or something in setopt's docstring (or the manual)
> mentioning the asynchrony would help.

setopt is a non-interactive version of defcustom.  Like defcustom will
not accept a value that contradicts the :type of the option, so will
setopt.  I don't think there's anything subtle to be documented here.