emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lexical-binding in CC-mode


From: Stefan Monnier
Subject: Re: lexical-binding in CC-mode
Date: Tue, 06 Apr 2021 12:49:19 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> The only thing I worry about is that l-b might not work properly in a
> previous Emacs release (for standalone CC Mode), and there doesn't
> appear to be a way of switching it on/off according to any criterion.
> In particular, the following doesn't seem to work, neither in Emacs 25.3
> or Emacs 28:
>
>     -*- eval: (setq lexical-binding (>= emacs-major-version 26)) -*-
>
> ..  That incantation leaves lexical-binding at nil, regardless of Emacs
> version.

Indeed, there's no such thing.  As always it's possible to work
something out if really needed, but the equivalent of the intended
behavior above is pretty cumbersome to obtain, so in all likelihood if
a need for something like this comes up, we'd want to find a different
workaround (e.g. by changing the code).

>> Of course, the change should be fully backward compatible (i.e. the
>> code sticks to the common subset of the two dialects).
> Do closures (for lambda forms) work in Emacs 25 and earlier?

Yes, they do.
There have a been a few changes that can impact compatibility, but
they've been rather minor.  The only ones I can think of are:
- performance (IIRC both for `condition-case` and for `unwind-protect`,
  the performance of lexical code was slightly improved in Emacs-25,
  and the cost of closure-creation ).
- `defun` could not refer to surrounding lexical variables in
  Emacs<24.3.  It's rare to nest `defun` within a `let` or another
  function, so it only affects very rare cases and these can be
  rewritten to use `defalias+lambda` if needed.
- I think there were a few bugs where macros could not rely on the
  value of `lexical-binding` to know if the returned code would be using
  the lexical dialect or not and these were fixed sometime before
  Emacs-25.  That's only relevant for the rare macros which want to generate
  different code for the different dialects (in most cases it's used to
  signal an error when the generated code only works with lexical-binding).

So I'm quite hopeful that there won't be any backward compatibility
issue for CC-mode in this respect.


        Setfan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]