unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Declaring 'lexical-binding: nil' obsolete
@ 2021-09-25 22:47 Stefan Kangas
  2021-09-25 23:17 ` Po Lu
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Stefan Kangas @ 2021-09-25 22:47 UTC (permalink / raw)
  To: Emacs developers; +Cc: Stefan Monnier

[-- Attachment #1: Type: text/plain, Size: 2197 bytes --]

Hi all,

Lexical binding has been with us since Emacs 24.1, released on
2012-06-10, almost ten years ago.  In Emacs 28.1, we will have no files
that do not use lexical-binding.[1]

I think it is time to formally declare the "lexical-binding:nil" dialect
of Emacs Lisp obsolete.

I have been thinking about what a roadmap could look like, and I would
like to propose a roadmap, best explained by this NEWS entry:

    ** 'lexical-binding: nil' is now obsolete.
    The old 'lexical-binding:nil' dialect of Emacs Lisp is now obsolete.
    Third-party code will need to be changed to support
    'lexical-binding:t' to run properly on Emacs in the future.

    We expect that this transition will be very smooth in most cases.
    See the Info node "(elisp) Converting to Lexical Binding" in
    the Emacs Lisp reference manual for some advice.

    For now, the most visible effect of this is that there is a warning
    when byte-compiling a file that does not specify lexical-binding to
    either nil or t.  This is intended as a stop-gap, and we will
    eventually warn if this variable is nil.

    The plan for phasing out 'lexical-binding:nil' is as follows:

    Emacs 28.1 - The byte-compiler warns if there is no 'lexical-binding'
                 cookie.

    Emacs 30.1 - The byte-compiler warns if there is no 'lexical-binding'
                 cookie, or if the cookie is 'lexical-binding:nil'.

    Emacs 32.1 - The warnings remain as before, and 'lexical-binding:t' is
                 the default.

The version numbers in this plan could be adjusted, but the ones I
propose should already give us most of the next decade before we
actually flip the switch.  In any case, whatever we decide now could
easily be adjusted in the future if needed.

Please see the attached patch for an idea of what this obsoletion might
amount to in terms of code.  It basically adds the following
byte-compiler warning:

    In toplevel form:
    lisp/foobar.el: Warning: First line should contain either
        "-*-lexical-binding:t-*-" or "-*-lexical-binding:nil-*-".

Footnotes:
[1] org-agenda.el still has no cookie, but it will once the latest
     version of Org-mode is merged into our tree.

[-- Attachment #2: 0001-Make-lexical-binding-nil-obsolete.patch --]
[-- Type: text/x-diff, Size: 4418 bytes --]

From f86c70ee0c7e69536c1741c30376e54dac7f8526 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sat, 25 Sep 2021 23:08:53 +0200
Subject: [PATCH] Make 'lexical-binding: nil' obsolete

* etc/NEWS: Announce obsoletion of 'lexical-binding: nil'.
* lisp/emacs-lisp/bytecomp.el (byte-compile-file): Warn if there
is no 'lexical-binding' statement on the first line.
* lisp/progmodes/elisp-mode.el (emacs-lisp-mode): Change tooltip to
say that "dynamic scoping mode" is obsolete.  Use error face.
Warn when opening a file that does not use 'lexical-binding:t'.
---
 etc/NEWS                     | 25 +++++++++++++++++++++++++
 lisp/emacs-lisp/bytecomp.el  |  4 ++++
 lisp/progmodes/elisp-mode.el | 12 +++++++++---
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index d77d34160b..11d04c4d2a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -3150,6 +3150,31 @@ This new 'etc-authors-mode' provides font-locking for displaying the
 \f
 * Incompatible Editing Changes in Emacs 28.1
 
+** 'lexical-binding: nil' is now obsolete.
+The old 'lexical-binding:nil' dialect of Emacs Lisp is now obsolete.
+Third-party code will need to be changed to support
+'lexical-binding:t' to run properly on Emacs in the future.
+
+We expect that this transition will be very smooth in most cases.
+See the Info node "(elisp) Converting to Lexical Binding" in
+the Emacs Lisp reference manual for some advice.
+
+For now, the most visible effect of this is that there is a warning
+when byte-compiling a file that does not specify lexical-binding to
+either nil or t.  This is intended as a stop-gap, and we will
+eventually warn if this variable is nil.
+
+The plan for phasing out 'lexical-binding:nil' is as follows:
+
+Emacs 28.1 - The byte-compiler warns if there is no 'lexical-binding'
+             cookie.
+
+Emacs 30.1 - The byte-compiler warns if there is no 'lexical-binding'
+             cookie, or if the cookie is 'lexical-binding:nil'.
+
+Emacs 32.1 - The warnings remain as before, and 'lexical-binding:t' is
+             the default.
+
 ---
 ** 'toggle-truncate-lines' now disables 'visual-line-mode'.
 This is for symmetry with 'visual-line-mode', which disables
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index d7da7a2149..3f220a4991 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -2050,7 +2050,11 @@ byte-compile-file
         (setq buffer-read-only nil
               filename buffer-file-name))
       ;; Don't inherit lexical-binding from caller (bug#12938).
+      ;; Warn if there is no 'lexical-binding' cookie.
       (unless (local-variable-p 'lexical-binding)
+        (byte-compile-warn "\
+First line should contain either \"-*-lexical-binding:t-*-\" \
+or \"-*-lexical-binding:nil-*-\".")
         (setq-local lexical-binding nil))
       ;; Set the default directory, in case an eval-when-compile uses it.
       (setq default-directory (file-name-directory filename)))
diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el
index 0b2395d976..096c4e18cb 100644
--- a/lisp/progmodes/elisp-mode.el
+++ b/lisp/progmodes/elisp-mode.el
@@ -281,9 +281,9 @@ emacs-lisp-mode
     (lexical-binding (:propertize "/l"
                       help-echo "Using lexical-binding mode")
                      (:propertize "/d"
-                      help-echo "Using old dynamic scoping mode\n\
+                      help-echo "Using obsolete dynamic scoping mode\n\
 mouse-1: Enable lexical-binding mode"
-		      face warning
+                      face error
 		      mouse-face mode-line-highlight
                       local-map ,elisp--dynlex-modeline-map)))
   "Major mode for editing Lisp code to run in Emacs.
@@ -319,7 +319,13 @@ emacs-lisp-mode
   (add-hook 'flymake-diagnostic-functions #'elisp-flymake-checkdoc nil t)
   (add-hook 'flymake-diagnostic-functions
               #'elisp-flymake-byte-compile nil t)
-  (add-hook 'context-menu-functions #'elisp-context-menu 10 t))
+  (add-hook 'context-menu-functions #'elisp-context-menu 10 t)
+  (when (and (not lexical-binding) buffer-file-name)
+    (message (format-message
+              (concat "Warning: `%s' is using the obsolete "
+                      "`lexical-binding:nil' version of "
+                      "Emacs Lisp")
+              (file-name-nondirectory buffer-file-name)))))
 
 ;; Font-locking support.
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2021-09-30 14:18 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-25 22:47 Declaring 'lexical-binding: nil' obsolete Stefan Kangas
2021-09-25 23:17 ` Po Lu
2021-09-26  0:04   ` Stefan Kangas
2021-09-26  0:13     ` Po Lu
2021-09-26  0:50       ` Stefan Kangas
2021-09-26  1:20         ` Po Lu
2021-09-26  2:37           ` Stefan Kangas
2021-09-26  2:55             ` Po Lu
2021-09-26  6:30         ` Eli Zaretskii
2021-09-26  6:08       ` Eli Zaretskii
2021-09-26  6:06     ` Eli Zaretskii
2021-09-25 23:56 ` Eduardo Ochs
2021-09-26  0:35   ` Stefan Kangas
2021-09-26  6:02 ` Eli Zaretskii
2021-09-26  6:36   ` Lars Ingebrigtsen
2021-09-27 22:35 ` Deprecating 'lexical-binding: nil' Richard Stallman
2021-09-27 23:09   ` Stefan Kangas
2021-09-28  1:42     ` Stefan Monnier
2021-09-30  6:03     ` Richard Stallman
2021-09-30 14:18       ` Steingold

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