Subject: Re: bug#59057: Emacs 29. Byte compiler sometimes forgets about a defvar.

From: Alan Mackenzie <[email-masked]>
Date: Wed, 9 Nov 2022 13:40:57 +0000

Hello, Stefan.

On Mon, Nov 07, 2022 at 16:31:32 -0500, Stefan Monnier wrote:
> >> (defvar VAR) does not "create a variable".
> > According to both its doc string and the Elisp manual it does.

> BTW, what I'm describing is how things have worked in `lexical-binding`
> since Emacs-24, basically.  A few corner cases didn't quite obey it
> (and I'm sure there are still a few remaining ones), but by and large
> this is how it has worked for the last 10 years.

OK, I see that now, having checked git logs and git blame.  There was a
bug report in 2018 about the documentation, which Noam Postavsky fixed.

The basic problem is that defvar is a dog's breakfast of a function.  In
fact, it's two distinct functions sharing a name.  These two functions
have little else to do with eachother.

And defvar appears to be the only function in Emacs where supplying nil
as an &optional argument has an effect different from omitting it.  This
is bad for anybody trying to learn Emacs Lisp.

Because defvar isn't a single function, it's impossible to document it
coherently without explicitly saying it's two functions.  I doubt the
powers that be would countenance such explicitness.  So the
documentation will continue to be confusing, and people like me will
continue to lose time sorting out what this hybrid function does.

I will alter the code in CC Mode which gave rise to this bug report.

>         Stefan

-- 
Alan Mackenzie (Nuremberg, Germany).