GNU bug report logs -
#20139
25.0.50; eval-buffer ignores lexical-binding
Previous Next
Reported by: Jorgen Schaefer <contact <at> jorgenschaefer.de>
Date: Wed, 18 Mar 2015 22:10:02 UTC
Severity: minor
Tags: fixed
Merged with 15070
Found in versions 24.3.50.1, 25.0.50
Fixed in version 27.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 20139 in the body.
You can then email your comments to 20139 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Wed, 18 Mar 2015 22:10:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Jorgen Schaefer <contact <at> jorgenschaefer.de>
:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org
.
(Wed, 18 Mar 2015 22:10:04 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Given a buffer with these contents:
(setq lexical-binding t)
(message "%s" (lambda () a))
Evaluating both lines with C-x C-e will message (closure (t) nil a), as
it should. But M-x eval-buffer will message (lambda nil a), i.e.
eval-buffer ignores the value of lexical-binding.
I do not think this is the intended behavior :-)
Regards,
Jorgen
In GNU Emacs 25.0.50.1 (x86_64-unknown-linux-gnu)
of 2015-02-21 on loki.jorgenschaefer.de
Repository revision: 9074a684990600abd9dfad0477c7cd1d2f339ed3
System Description: Debian GNU/Linux 7.8 (wheezy)
Configured using:
`configure --without-x'
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Thu, 19 Mar 2015 03:11:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 20139 <at> debbugs.gnu.org (full text, mbox):
> (setq lexical-binding t)
> (message "%s" (lambda () a))
This is wrong. The `setq' above is an expression evaluated at run-time,
whereas what you want to say (that this code is written in the lexical
version of the Elisp language) is something that needs to be known before
evaluation proceeds.
You can do M-: (setq lexical-binding t) from that buffer in order to
tell Emacs that the code in the buffer uses the lexical
version of the Elisp language, or better, you should put a "-*-
lexical-binding:t -*-" at the top of the file.
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Thu, 19 Mar 2015 07:34:01 GMT)
Full text and
rfc822 format available.
Message #11 received at 20139 <at> debbugs.gnu.org (full text, mbox):
On Thu, Mar 19, 2015 at 4:10 AM, Stefan Monnier
<monnier <at> iro.umontreal.ca> wrote:
>> (setq lexical-binding t)
>> (message "%s" (lambda () a))
>
> This is wrong. The `setq' above is an expression evaluated at run-time,
> whereas what you want to say (that this code is written in the lexical
> version of the Elisp language) is something that needs to be known before
> evaluation proceeds.
I am sorry for the confusion; I added the `setq' form so it is easier
to C-x C-e it. The
bug I describe happens in a buffer with `lexical-binding' set, no
matter which way it
is set. I.e. the following snippet will message (lambda nil t) and
then (closure (t) nil t):
(with-temp-buffer
(setq lexical-binding t)
(insert "(message \"%S\" (lambda () t))")
(eval-buffer)
(eval-region (point-min) (point-max)))
Regards,
Jorgen
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Thu, 19 Mar 2015 09:57:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 20139 <at> debbugs.gnu.org (full text, mbox):
Jorgen Schäfer <contact <at> jorgenschaefer.de> writes:
> . I.e. the following snippet will message (lambda nil t) and
> then (closure (t) nil t):
>
> (with-temp-buffer
> (setq lexical-binding t)
> (insert "(message \"%S\" (lambda () t))")
> (eval-buffer)
> (eval-region (point-min) (point-max)))
And this will reverse the behaviour :
(with-temp-buffer
(insert ";; -*- lexical-binding: t; -*-\n(message \"%S\" (lambda () t))")
(eval-buffer)
(eval-region (point-min) (point-max)))
IOW eval-buffer obeys the "file"-local variable by calling
specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf) ? Qt : Qnil);
while eval-region simply uses the current value of lexical-binding.
--
Nicolas
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Thu, 19 Mar 2015 14:16:02 GMT)
Full text and
rfc822 format available.
Message #17 received at 20139 <at> debbugs.gnu.org (full text, mbox):
> IOW eval-buffer obeys the "file"-local variable by calling
> specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf) ? Qt : Qnil);
> while eval-region simply uses the current value of lexical-binding.
Indeed, and I don't think we can easily change either of these.
Jorgen, what is the original problem you're trying to solve?
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Thu, 19 Mar 2015 14:53:02 GMT)
Full text and
rfc822 format available.
Message #20 received at 20139 <at> debbugs.gnu.org (full text, mbox):
On Thu, Mar 19, 2015 at 3:40 PM, Stefan Monnier
<monnier <at> iro.umontreal.ca> wrote:
>> I am extracting Emacs Lisp code from a markdown file and evaluating
>> it. I can easily use eval-region instead of eval-buffer, so I have no
>> unsolved problem at the moment. Just figured I'd report this issue.
>
> The basic rule for me is "never (setq lexical-binding ...)". Instead,
> either add the file-local magic marker and manipulate it as a whole
> buffer/file, or let-bind lexical-binding around the call to
> `eval-region', or pass the second arg to `eval'.
Let-binding `lexical-binding' does not affect `eval-buffer', either.
(with-temp-buffer
(let ((lexical-binding t))
(insert "(message \"%S\" (lambda () t))")
(eval-buffer)
(eval-region (point-min) (point-max))))
(lambda nil t)
(closure (t) nil t)
Regards,
Jorgen
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Thu, 19 Mar 2015 15:50:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 20139 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier wrote:
> You can do M-: (setq lexical-binding t) from that buffer in order to
> tell Emacs that the code in the buffer uses the lexical
Apparently that doesn't work: http://debbugs.gnu.org/15070
Merged 15070 20139.
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Thu, 19 Mar 2015 15:52:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Thu, 19 Mar 2015 16:29:01 GMT)
Full text and
rfc822 format available.
Message #28 received at 20139 <at> debbugs.gnu.org (full text, mbox):
>> The basic rule for me is "never (setq lexical-binding ...)". Instead,
>> either add the file-local magic marker and manipulate it as a whole
>> buffer/file, or let-bind lexical-binding around the call to
>> `eval-region', or pass the second arg to `eval'.
> Let-binding `lexical-binding' does not affect `eval-buffer', either.
Yes: note that I distinguish between "whole buffer/file" and the other
case (the other case being when you evaluate some chunk of code).
Stefan
Information forwarded
to
bug-gnu-emacs <at> gnu.org
:
bug#20139
; Package
emacs
.
(Mon, 07 Oct 2019 15:26:03 GMT)
Full text and
rfc822 format available.
Message #31 received at 20139 <at> debbugs.gnu.org (full text, mbox):
Stefan Monnier <monnier <at> IRO.UMontreal.CA> writes:
>> IOW eval-buffer obeys the "file"-local variable by calling
>> specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf) ?
>> Qt : Qnil);
>> while eval-region simply uses the current value of lexical-binding.
>
> Indeed, and I don't think we can easily change either of these.
> Jorgen, what is the original problem you're trying to solve?
So `eval-buffer' ignores the buffer-local value of `lexical-binding',
and that's a feature. So I think we should just document that?
I've now done so in Emacs 27.
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
Added tag(s) fixed.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 07 Oct 2019 15:26:03 GMT)
Full text and
rfc822 format available.
bug marked as fixed in version 27.1, send any further explanations to
15070 <at> debbugs.gnu.org and E Sabof <esabof <at> gmail.com>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org
.
(Mon, 07 Oct 2019 15:26:03 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Tue, 05 Nov 2019 12:24:05 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 166 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.