[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [External] : Re: Conditional binding and testing of `lexical-binding
From: |
Drew Adams |
Subject: |
RE: [External] : Re: Conditional binding and testing of `lexical-binding' |
Date: |
Sun, 2 Jan 2022 23:01:21 +0000 |
> > What's the best way, or a reasonable way,
> > of setting `lexical-binding' conditionally,
>
> I don't know what you mean by that,
And yet I gave details to make it clear, as
well as examples. Which part(s) didn't you
understand?
> nor why you think it's necessary for:
If you didn't understand what "it" is, then
how is it that you think it's not necessary
for what follows?
> > so a library can be used with both Emacs
> > versions that support lexical binding
> > and versions that don't support it?
There you have it: setting it conditionally
so it can be tested, to check whether the
Emacs version being used supports lexical
binding.
> Adding the -*- lexical-binding:t -*- at the
> beginning of the file does that
Thanks for confirming that this is the best
(the only?) way to do it.
If you read my mail you'll see that I figured
out, by experimenting, that it's _sufficient_
to do that, to be able to test even with old
Emacs versions (which don't have variable
`lexical-binding').
This isn't obvious (and it's undocumented,
AFAICT).
It wasn't clear, before experimenting, what
that declaration would mean for Emacs 23 or
earlier - which behavior:
1. It implicitly creates a defvar and sets the
value to `t'.
2. It's ignored, so the variable is undefined
(unbound).
3. Something else.
Before experimenting, I was guessing #1. But
it seems to be #2.
Knowing this is important, for testing the
variable. As I said, the test I apparently
need is this:
(and (boundp 'lexical-binding)
lexical-binding)
[Emacs 22 has `bound-and-true-p', but older
versions don't have it.]
If it were #1 then this wouldn't help. The
var would be `t' for all Emacs versions, even
those for which that variable has no effect.
Please consider documenting this in the manual.
It _looks_ very much like the declaration sets
var `lexical-binding' to t, regardless of the
Emacs version. But it seems it does not.
> (this is used by CC-mode, for example).
I don't see that in cc-mode.el for the latest
Emacs release (which is 27.2).
Even if it'll be present for Emacs 28 or later
(when released), that's no proof or even a
hint that the given library is compatible with
Emacs 23, 22,...
Re: Conditional binding and testing of `lexical-binding', Stefan Monnier, 2022/01/02
- RE: [External] : Re: Conditional binding and testing of `lexical-binding',
Drew Adams <=