From f86c70ee0c7e69536c1741c30376e54dac7f8526 Mon Sep 17 00:00:00 2001 From: Stefan Kangas 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 * 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