all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
@ 2015-03-18 22:09 Jorgen Schaefer
  2015-03-19  3:10 ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Jorgen Schaefer @ 2015-03-18 22:09 UTC (permalink / raw)
  To: 20139

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'






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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
  2015-03-18 22:09 bug#20139: 25.0.50; eval-buffer ignores lexical-binding Jorgen Schaefer
@ 2015-03-19  3:10 ` Stefan Monnier
  2015-03-19  7:33   ` Jorgen Schäfer
  2015-03-19 15:49   ` Glenn Morris
  0 siblings, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2015-03-19  3:10 UTC (permalink / raw)
  To: Jorgen Schaefer; +Cc: 20139

> (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





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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
  2015-03-19  3:10 ` Stefan Monnier
@ 2015-03-19  7:33   ` Jorgen Schäfer
  2015-03-19  9:56     ` Nicolas Richard
  2015-03-19 15:49   ` Glenn Morris
  1 sibling, 1 reply; 9+ messages in thread
From: Jorgen Schäfer @ 2015-03-19  7:33 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 20139

On Thu, Mar 19, 2015 at 4:10 AM, Stefan Monnier
<monnier@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





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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
  2015-03-19  7:33   ` Jorgen Schäfer
@ 2015-03-19  9:56     ` Nicolas Richard
  2015-03-19 14:15       ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Nicolas Richard @ 2015-03-19  9:56 UTC (permalink / raw)
  To: Jorgen Schäfer; +Cc: 20139

Jorgen Schäfer <contact@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





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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
  2015-03-19  9:56     ` Nicolas Richard
@ 2015-03-19 14:15       ` Stefan Monnier
       [not found]         ` <CALqDrSccFR=TMo=r96v_ODCJbq=afrcaXCse77shekyRWwEyxA@mail.gmail.com>
  2019-10-07 15:25         ` Lars Ingebrigtsen
  0 siblings, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2015-03-19 14:15 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: Jorgen Schäfer, 20139

> 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





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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
       [not found]           ` <jwvmw3959zl.fsf-monnier+emacsbugs@gnu.org>
@ 2015-03-19 14:52             ` Jorgen Schäfer
  2015-03-19 16:28               ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Jorgen Schäfer @ 2015-03-19 14:52 UTC (permalink / raw)
  To: Stefan Monnier, 20139

On Thu, Mar 19, 2015 at 3:40 PM, Stefan Monnier
<monnier@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





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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
  2015-03-19  3:10 ` Stefan Monnier
  2015-03-19  7:33   ` Jorgen Schäfer
@ 2015-03-19 15:49   ` Glenn Morris
  1 sibling, 0 replies; 9+ messages in thread
From: Glenn Morris @ 2015-03-19 15:49 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Jorgen Schaefer, 20139

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





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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
  2015-03-19 14:52             ` Jorgen Schäfer
@ 2015-03-19 16:28               ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2015-03-19 16:28 UTC (permalink / raw)
  To: Jorgen Schäfer; +Cc: 20139

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





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

* bug#20139: 25.0.50; eval-buffer ignores lexical-binding
  2015-03-19 14:15       ` Stefan Monnier
       [not found]         ` <CALqDrSccFR=TMo=r96v_ODCJbq=afrcaXCse77shekyRWwEyxA@mail.gmail.com>
@ 2019-10-07 15:25         ` Lars Ingebrigtsen
  1 sibling, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2019-10-07 15:25 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Jorgen Schäfer, Nicolas Richard, 20139, 15070

Stefan Monnier <monnier@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





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

end of thread, other threads:[~2019-10-07 15:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-18 22:09 bug#20139: 25.0.50; eval-buffer ignores lexical-binding Jorgen Schaefer
2015-03-19  3:10 ` Stefan Monnier
2015-03-19  7:33   ` Jorgen Schäfer
2015-03-19  9:56     ` Nicolas Richard
2015-03-19 14:15       ` Stefan Monnier
     [not found]         ` <CALqDrSccFR=TMo=r96v_ODCJbq=afrcaXCse77shekyRWwEyxA@mail.gmail.com>
     [not found]           ` <jwvmw3959zl.fsf-monnier+emacsbugs@gnu.org>
2015-03-19 14:52             ` Jorgen Schäfer
2015-03-19 16:28               ` Stefan Monnier
2019-10-07 15:25         ` Lars Ingebrigtsen
2015-03-19 15:49   ` Glenn Morris

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.