]> git.eshelyaron.com Git - emacs.git/commitdiff
(lexical-binding): Allow changing the default value (bug#74145)
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 18 Feb 2025 20:37:50 +0000 (15:37 -0500)
committerEshel Yaron <me@eshelyaron.com>
Tue, 18 Feb 2025 21:34:16 +0000 (22:34 +0100)
* lisp/loadup.el: Preserve (default-toplevel-value 'lexical-binding).

* src/lread.c (Fload, Feval_buffer): Obey (default-toplevel-value
'lexical-binding).

* doc/lispintro/emacs-lisp-intro.texi (Lexical vs Dynamic Binding
Example): Use the lexical dialect also for the dynamic
scoping example.
* doc/lispref/edebug.texi (Edebug Eval): Remove long-obsolete mention
of Edebug support for `lexical-let`.

(cherry picked from commit d685d21e8ae0cee566420d4dd68586f018b2ce0b)

doc/lispintro/emacs-lisp-intro.texi
doc/lispref/edebug.texi
doc/lispref/variables.texi
lisp/loadup.el
src/lread.c

index 763478bfee41ff5d71038049b586df9251ee6a42..fe008d5c5941a0fdedad31c12675f161cc57b79e 100644 (file)
@@ -3844,7 +3844,9 @@ well.  When executing @code{getx}, the current global value of
 If we use dynamic binding instead, the behavior is different:
 
 @example
-;;; -*- lexical-binding: nil -*-
+;;; -*- lexical-binding: t -*-
+
+(defvar x) ;; Use dynamic binding for 'x'.
 
 (setq x 0)
 
@@ -3866,8 +3868,9 @@ binding.  This time, @code{getx} doesn't see the global value for
 @code{x}, since its binding is below the one from our @code{let}
 expression in the stack of bindings.
 
-(Some variables are also ``special'', and they are always dynamically
-bound even when @code{lexical-binding} is @code{t}.  @xref{defvar, ,
+(The @code{defvar} declaration above is said to make the variable
+``special'', which causes it to obey the dynamic binding rules instead of
+the default binding rules.  @xref{defvar, ,
 Initializing a Variable with @code{defvar}}.)
 
 @node if
index e234db6fce53dda525c80e18d061981b06e347b4..1583659103280856d6fa6423ac42097332026851 100644 (file)
@@ -722,13 +722,6 @@ lists).  Any other prefix will result in the value being
 pretty-printed in a separate buffer.
 @end table
 
-@cindex lexical binding (Edebug)
-  Edebug supports evaluation of expressions containing references to
-lexically bound symbols created by the following constructs in
-@file{cl.el}: @code{lexical-let}, @code{macrolet}, and
-@code{symbol-macrolet}.
-@c FIXME?  What about lexical-binding = t?
-
 @node Eval List
 @subsection Evaluation List Buffer
 
index db9a44cda1d23cf88d9025c057b6ae0528dcfc12..ce7bd27eef6acc5fa864dfd5aa803515b9f947c3 100644 (file)
@@ -285,7 +285,7 @@ previous example is equivalent to using nested @code{let} bindings:
 @defspec letrec (bindings@dots{}) forms@dots{}
 This special form is like @code{let*}, but all the variables are bound
 before any of the local values are computed.  The values are then
-assigned to the locally bound variables.  This is only useful when
+assigned to the locally bound variables.  This is useful only when
 lexical binding is in effect, and you want to create closures that
 refer to bindings that would otherwise not yet be in effect when using
 @code{let*}.
@@ -351,7 +351,7 @@ A function call is in the tail position if it's the very last thing
 done so that the value returned by the call is the value of @var{body}
 itself, as is the case in the recursive call to @code{sum} above.
 
-@code{named-let} can only be used when lexical-binding is enabled.
+@code{named-let} can be used only when lexical-binding is enabled.
 @xref{Lexical Binding}.
 @end defspec
 
@@ -392,7 +392,7 @@ object can be; but it is still a value.  If a variable is void, trying
 to evaluate the variable signals a @code{void-variable} error, instead
 of returning a value.
 
-  Under the optional lexical scoping rule, the value cell only holds
+  Under the optional lexical scoping rule, the value cell holds only
 the variable's global value---the value outside of any lexical binding
 construct.  When a variable is lexically bound, the local value is
 determined by the lexical environment; hence, variables can have local
@@ -710,8 +710,8 @@ completely.
   The usual way to reference a variable is to write the symbol which
 names it.  @xref{Symbol Forms}.
 
-  Occasionally, you may want to reference a variable which is only
-determined at run time.  In that case, you cannot specify the variable
+  Occasionally, you may want to reference a variable which is determined
+only at run time.  In that case, you cannot specify the variable
 name in the text of the program.  You can use the @code{symbol-value}
 function to extract the value.
 
@@ -1991,8 +1991,8 @@ to use this, @pxref{Auto Major Mode}.
 
 @defvar permanently-enabled-local-variables
 Some local variable settings will, by default, be heeded even if
-@code{enable-local-variables} is @code{nil}.  By default, this is only
-the case for the @code{lexical-binding} local variable setting, but
+@code{enable-local-variables} is @code{nil}.  By default, this is the
+case only for the @code{lexical-binding} local variable setting, but
 this can be controlled by using this variable, which is a list of
 symbols.
 @end defvar
index 7d77b1f24e5b33090fe3cfa212acd3bb653faafe..cf253980f9f7932017027b34fd855eb15c755f6f 100644 (file)
@@ -617,9 +617,9 @@ directory got moved.  This is set to be a pair in the form of:
           (unwind-protect
               (let ((tmp-dump-mode dump-mode)
                     (dump-mode nil)
-                    ;; Set `lexical-binding' to nil by default
+                    ;; Set `lexical-binding' to its default value
                     ;; in the dumped Emacs.
-                    (lexical-binding nil))
+                    (lexical-binding (default-toplevel-value 'lexical-binding)))
                 (if (member tmp-dump-mode '("pdump" "pbootstrap"))
                     (dump-emacs-portable (expand-file-name output invocation-directory))
                   (dump-emacs output (if (eq system-type 'ms-dos)
index 46c705e5c760de62718d54749984b239f971925f..df1caaf57324c5a34ed72f4e1aaf63db64bf5f61 100644 (file)
@@ -1720,8 +1720,11 @@ Return t if the file exists and loads successfully.  */)
     }
   else
     {
-      if (lisp_file_lexical_cookie (Qget_file_char) == Cookie_Lex)
-        Fset (Qlexical_binding, Qt);
+      lexical_cookie_t lexc = lisp_file_lexical_cookie (Qget_file_char);
+      Fset (Qlexical_binding,
+           (lexc == Cookie_Lex ? Qt
+            : lexc == Cookie_Dyn ? Qnil
+            : Fdefault_toplevel_value (Qlexical_binding)));
 
       if (! version || version >= 22)
         readevalloop (Qget_file_char, &input, hist_file_name,
@@ -2606,8 +2609,11 @@ This function preserves the position of point.  */)
   specbind (Qstandard_output, tem);
   record_unwind_protect_excursion ();
   BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
+  lexical_cookie_t lexc = lisp_file_lexical_cookie (buf);
   specbind (Qlexical_binding,
-           lisp_file_lexical_cookie (buf) == Cookie_Lex ? Qt : Qnil);
+           lexc == Cookie_Lex ? Qt
+           : lexc == Cookie_Dyn ? Qnil
+           : Fdefault_toplevel_value (Qlexical_binding));
   BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
   readevalloop (buf, 0, filename,
                !NILP (printflag), unibyte, Qnil, Qnil, Qnil);