(lexical-binding): Allow changing the default value (bug#74145)
* 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`.
This commit is contained in:
parent
790c2f7c1c
commit
d685d21e8a
6 changed files with 32 additions and 22 deletions
|
@ -3845,7 +3845,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)
|
||||
|
||||
|
@ -3867,8 +3869,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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
8
etc/NEWS
8
etc/NEWS
|
@ -1293,6 +1293,14 @@ Previously, its argument was always evaluated using dynamic binding.
|
|||
|
||||
* Lisp Changes in Emacs 31.1
|
||||
|
||||
---
|
||||
** You can change the default value of 'lexical-binding'.
|
||||
While the default is still the use dynamic binding dialect of ELisp
|
||||
in those places that don't explicitly set 'lexical-binding' you can
|
||||
change it globally with:
|
||||
|
||||
(set-default-toplevel-value 'lexical-binding t)
|
||||
|
||||
+++
|
||||
** New functions 'plusp' and 'minusp'.
|
||||
They return non-nil if a number is positive or negative, respectively,
|
||||
|
|
|
@ -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)
|
||||
|
|
12
src/lread.c
12
src/lread.c
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue