all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: RE: [External] : Re: Conditional binding and testing of `lexical-binding'
Date: Sun, 2 Jan 2022 23:01:21 +0000	[thread overview]
Message-ID: <SJ0PR10MB5488502CF4FA5727CA9A2307F3489@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <jwvk0fivvv8.fsf-monnier+emacs@gnu.org>

> > 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,...



      reply	other threads:[~2022-01-02 23:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-01 22:24 Conditional binding and testing of `lexical-binding' Drew Adams
2022-01-02 12:36 ` LdBeth
2022-01-02 12:41   ` Po Lu
2022-01-02 18:29     ` Stefan Monnier
2022-01-02 23:01       ` [External] : " Drew Adams
2022-01-02 23:01     ` Drew Adams
2022-01-03  0:49       ` Po Lu
2022-01-02 23:01   ` Drew Adams
2022-01-03  3:09     ` LdBeth
2022-01-03  3:31       ` Drew Adams
2022-01-02 18:27 ` Stefan Monnier
2022-01-02 23:01   ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=SJ0PR10MB5488502CF4FA5727CA9A2307F3489@SJ0PR10MB5488.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.