Subject: Re: bug#70137: 30.0.50; pp-macroexpand-last-sexp buffers should turn lexical binding on

From: Augusto Stoffel <[email-masked]>
Date: Sun, 14 Apr 2024 09:42:12 +0200

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.

>From 8d81704d61153f13de516475f4e0ab53e8e94f11 Mon Sep 17 00:00:00 2001
From: Augusto Stoffel <[email-masked]>
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