Subject: Re: bug#77883: 31.0.50; C-c C-e in *scratch* generates a missing lexical binding cookie warning

From: Eli Zaretskii <[email-masked]>
Date: Fri, 18 Apr 2025 15:13:40 +0300

> From: Michael Heerdegen <[email-masked]>
> Cc: Sean Whitton <[email-masked]>,  Stefan Monnier
>  <[email-masked]>,  [email-masked]
> Date: Fri, 18 Apr 2025 13:12:48 +0200
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> > IMO, it's a bug, because "C-x C-e" doesn't generate any such warnings,
> > and lexical-binding is t in *scratch* anyway.
> 
> I agree it is a bug.
> 
> C-c C-e calls `eval-buffer' which "ignores the current value of the
> `lexical-binding' variable.  Instead it will heed any
> -*- lexical-binding: t -*- settings in the buffer, and if there is no such
> setting, the buffer will be evaluated without lexical binding."
> 
> Not good in this case.

Is it good in any other case?

I mean, what's the logic behind ignoring the current value of
lexical-binding, but heeding the cookie? let alone defaulting to
dynamic binding if there's no cookie?  If the reason is backward
compatibility, I think I'd like to see the details: where would
changing this cause problems?

And note that this aspect of the eval-buffer's behavior is not
documented in the ELisp manual, which is also not a good thing.