Subject: Re: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong

From: Stefan Monnier <[email-masked]>
Date: Thu, 19 Nov 2020 15:23:45 -0500

>> This is a bug, indeed.  It should be 123 at this point.
> That's one perspective, but it seems less consistent with the
> documentation and with expected behavior.

That's the way all other variables behave:

    (defvar-local sm-foo 1)
    (let ((sm-foo 23))
      (setq sm-foo 45)
      (list sm-foo
            (with-temp-buffer sm-foo)))

and I think it's asking for trouble if

    (let ((sm-foo 23))
      ...)

behaves differently from

    (let (sm-foo)
      (setq sm-foo 23)
      ...)

> and here, we are setting it, with setq.  It would seem that it should
> become buffer-local, then.  Indeed, that's the current behavior, that it
> becomes "pseudo-buffer-local", in that the value is different in this
> buffer from every other buffer.  (But local-variable-p returns nil,
> which is the only indication that something weird is going on.)

Indeed the current behavior is clearly buggy.  Historically, the
behavior of PER_BUFFER variables has been even more unlike that of
`make-variable-buffer-local` but over the years, I've made efforts to
make them behave the same.  Clearly, I missed this spot.

        Stefan