From: Drew Adams <drew.adams@oracle.com>
To: LdBeth <andpuke@foxmail.com>
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:09 +0000 [thread overview]
Message-ID: <SJ0PR10MB548898B6BA9D69C29FABB6A9F3489@SJ0PR10MB5488.namprd10.prod.outlook.com> (raw)
In-Reply-To: <tencent_4654C7D46AEE8FCFCDB2BBC831BAC70C8305@qq.com>
> > (if (and (boundp 'lexical-binding)
> > lexical-binding)
> > (lambda (y) (something x y))
> > `(lambda (y) (something ',x y)))
>
> You may use `static-if' to benifit from
> byte-compiling.
I see no `static-if' in any Emacs release, from
emacs -Q. (The most recent Emacs release is 27.2.)
Certainly it's not present in Emacs 23 or earlier,
which is where there's no variable `lexical-let'.
So clearly it can't be used in Emacs 23 to test
whether lexical binding is supported.
I wonder whether you might have misread my post.
This is about a library that intends to be usable
with Emacs releases prior to Emacs 24 (where that
var is introduced), as well as with later Emacs
releases.
This is not about _converting_ a library to always
use `lexical-binding', which would only be useful
for Emacs 24 and later.
It's about being able to take advantage of
`lexical-binding' for Emacs 24+, while still being
compatible with versions earlier than 24.
> > But my question is really about conditionally
> > _setting_ `lexical-binding', so it can be tested.
>
> I think the "lispy" way is to use:
> (provide 'lexical-binding)> and use `featurep' to test it.
See above, or reread my first post. (And none of
my code is providing feature `lexical-binding'.
Just setting that var to t does not "provide" it
as a supported feature. It's either supported by
a given version of Emacs or it's not.)
> A more reliable way
To do what? This apparently has nothing to do
with the quoted text it followed (?).
> is to test
> (static-if (assoc 'lexical-binding (buffer-local-variables))
> (provide 'lexical-binding))
> instead of doing `boundp' test.
Sorry, but that makes no sense to me. Emacs
support for `lexical-binding' is true (for
Emacs 24+) regardless of whether that var is
buffer-local variable (and with any value).
> > Is this the thing to do? If not, what advice
> > do you have for adapting a library to use
> > lexical binding when available (Emacs 24+) but
> > to also work when it's unavailable (Emacs < 24)?
>
> > [The doc just tells you how to convert code to
> > use lexical binding. I see nothing about how
> > to code compatibly for old and new Emacs.]
>
> Well, I think it's fine to just keep that library as-is.
> Even in the current lastest release there are still many
> builtin packages are not converted to using lexical binding
> at all. Just name a few I know, supercite, enriched-mode
Certainly it's OK to keep such a library as is.
I've been doing that for years.
But I'm asking how to let it take advantage of
lexical binding when that's available. That's
the question I posed. I said how I intend to
do that, but I asked if there's a better way.
next prev parent 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 [this message]
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 ` [External] : " Drew Adams
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SJ0PR10MB548898B6BA9D69C29FABB6A9F3489@SJ0PR10MB5488.namprd10.prod.outlook.com \
--to=drew.adams@oracle.com \
--cc=andpuke@foxmail.com \
--cc=emacs-devel@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).