unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
@ 2024-04-02  6:01 Augusto Stoffel
  2024-04-02 11:59 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Augusto Stoffel @ 2024-04-02  6:01 UTC (permalink / raw)
  To: 70137

If you call pp-macroexpand-last-sexp in a buffer with lexical binding,
the resulting *Pp Macroexpand Output* buffer has lexical binding turned
off.

The problem with this is that if you now go the *Pp Macroexpand Output*
buffer and call pp-macroexpand-last-sexp again, this second macro
expansion step may not reflect what would happen in the original buffer;
I don't recall an example, but some macros expand differently in the two
variable scoping modes.





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

* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
  2024-04-02  6:01 bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on Augusto Stoffel
@ 2024-04-02 11:59 ` Eli Zaretskii
  2024-04-02 20:56 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-10 21:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2024-04-02 11:59 UTC (permalink / raw)
  To: Augusto Stoffel, Stefan Monnier; +Cc: 70137

> From: Augusto Stoffel <arstoffel@gmail.com>
> Date: Tue, 02 Apr 2024 08:01:18 +0200
> 
> If you call pp-macroexpand-last-sexp in a buffer with lexical binding,
> the resulting *Pp Macroexpand Output* buffer has lexical binding turned
> off.
> 
> The problem with this is that if you now go the *Pp Macroexpand Output*
> buffer and call pp-macroexpand-last-sexp again, this second macro
> expansion step may not reflect what would happen in the original buffer;
> I don't recall an example, but some macros expand differently in the two
> variable scoping modes.

Adding Stefan.





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

* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
  2024-04-02  6:01 bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on Augusto Stoffel
  2024-04-02 11:59 ` Eli Zaretskii
@ 2024-04-02 20:56 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-10 21:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2 siblings, 0 replies; 8+ messages in thread
From: Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-02 20:56 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: 70137

Augusto Stoffel <arstoffel@gmail.com> writes:

> If you call pp-macroexpand-last-sexp in a buffer with lexical binding,
> the resulting *Pp Macroexpand Output* buffer has lexical binding turned
> off.

Same as with any other displayed pp output buffer btw, or any temp
buffer.  All inherit the global lexical-binding -> nil binding.  Not
ideal indeed.

Michael.





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

* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
  2024-04-02  6:01 bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on Augusto Stoffel
  2024-04-02 11:59 ` Eli Zaretskii
  2024-04-02 20:56 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-10 21:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-14  7:42   ` Augusto Stoffel
  2 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-10 21:39 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: 70137

> If you call pp-macroexpand-last-sexp in a buffer with lexical binding,
> the resulting *Pp Macroexpand Output* buffer has lexical binding turned off.
>
> The problem with this is that if you now go the *Pp Macroexpand Output*
> buffer and call pp-macroexpand-last-sexp again, this second macro
> expansion step may not reflect what would happen in the original buffer;
> I don't recall an example, but some macros expand differently in the two
> variable scoping modes.

Indeed.  `dolist` and `dotimes` were such examples (tho nowadays they
return the same result).  Most other examples I can think of signal
an error when used without lexical binding.  There are a few more subtle
examples where the macro tests `macroexp--dynamic-variable-p`.

Do you happen to have a patch to propagate the value of
`lexical-binding` to the new buffer?


        Stefan






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

* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
  2024-04-10 21:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-14  7:42   ` Augusto Stoffel
  2024-04-17 17:43     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 8+ messages in thread
From: Augusto Stoffel @ 2024-04-14  7:42 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 70137

[-- Attachment #1: Type: text/plain, Size: 461 bytes --]

On Wed, 10 Apr 2024 at 17:39, Stefan Monnier wrote:

> Do you happen to have a patch to propagate the value of
> `lexical-binding` to the new buffer?

This would be the patch to propagate the lexical binding value.  (A less
magical alternative I guess would be to just always set it to t.  Who
needs to debug non-lexical code these days anyway?)

It doesn't cover the new `pp-insert-short-sexp'.  Here again setting
lexical-binding=t by default might be okay.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Propagate-lexical-binding-value-to-pp-buffers.patch --]
[-- Type: text/x-patch, Size: 1281 bytes --]

From 8d81704d61153f13de516475f4e0ab53e8e94f11 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <arstoffel@gmail.com>
Date: Sun, 14 Apr 2024 09:36:05 +0200
Subject: [PATCH] Propagate 'lexical-binding' value to pp buffers

See bug#70137.

* lisp/emacs-lisp/pp.el (pp-display-expression): Set lexical-binding to
match the value in the calling buffer.
---
 lisp/emacs-lisp/pp.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index d586fc59939..f89807c37be 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -327,7 +327,8 @@ pp-display-expression
 
 If a temporary buffer is needed for representation, it will be named
 after OUT-BUFFER-NAME."
-  (let* ((old-show-function temp-buffer-show-function)
+  (let* ((lexical lexical-binding)
+         (old-show-function temp-buffer-show-function)
 	 ;; Use this function to display the buffer.
 	 ;; This function either decides not to display it at all
 	 ;; or displays it in the usual way.
@@ -357,6 +358,7 @@ pp-display-expression
         (pp expression))
       (with-current-buffer standard-output
 	(emacs-lisp-mode)
+        (setq lexical-binding lexical)
 	(setq buffer-read-only nil)
         (setq-local font-lock-verbose nil)))))
 
-- 
2.44.0


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

* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
  2024-04-14  7:42   ` Augusto Stoffel
@ 2024-04-17 17:43     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2024-04-17 18:55       ` Augusto Stoffel
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-17 17:43 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: 70137

> This would be the patch to propagate the lexical binding value.

LGTM.  Can you install it, or do you want me to do it?

> (A less magical alternative I guess would be to just always set it to
> t.  Who needs to debug non-lexical code these days anyway?)

Not sure why you think it'd be less magical.  🙂

> It doesn't cover the new `pp-insert-short-sexp'.  Here again setting
> lexical-binding=t by default might be okay.

`pp-insert-short-sexp` should use `lisp-data-mode` rather than
`emacs-lisp-mode` anyway.


        Stefan






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

* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
  2024-04-17 17:43     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2024-04-17 18:55       ` Augusto Stoffel
  2024-04-17 21:03         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 8+ messages in thread
From: Augusto Stoffel @ 2024-04-17 18:55 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 70137

On Wed, 17 Apr 2024 at 13:43, Stefan Monnier wrote:

> LGTM.  Can you install it, or do you want me to do it?

I don't have commit access to the repo and I absolutely don't mind the
status quo :-).





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

* bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on
  2024-04-17 18:55       ` Augusto Stoffel
@ 2024-04-17 21:03         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-04-17 21:03 UTC (permalink / raw)
  To: Augusto Stoffel; +Cc: 70137-done

Thanks, pushed to `master`, closing,


        Stefan






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

end of thread, other threads:[~2024-04-17 21:03 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02  6:01 bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on Augusto Stoffel
2024-04-02 11:59 ` Eli Zaretskii
2024-04-02 20:56 ` Michael Heerdegen via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-10 21:39 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-14  7:42   ` Augusto Stoffel
2024-04-17 17:43     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-17 18:55       ` Augusto Stoffel
2024-04-17 21:03         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).