emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG?][PATCH] Should the `lexical-binding' variable be bound during src block with :lexical t? [9.4.6 (9.4.6-ga451f9 @ /home/n/.emacs.d/straight/build/org/)]
@ 2021-09-09 22:58 No Wayman
  2021-09-10  1:53 ` Tim Cross
  2021-09-10  6:32 ` Timothy
  0 siblings, 2 replies; 6+ messages in thread
From: No Wayman @ 2021-09-09 22:58 UTC (permalink / raw)
  To: emacs-orgmode

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


I ran into this with some code I'm writing which checks against 
`lexical-binding'.
Should the following result in "lexical binding enabled" or 
"lexical binding disabled"?:

#+begin_src emacs-lisp :lexical t
(message "lexical binding %sabled" (if lexical-binding "en" 
"dis"))
#+end_src

Currently the `lexical-binding' variable is not bound because 
`org-babel-execute:emacs-lisp'
passes t to `eval', which enables lexical binding, but does not 
bind the `lexical-binding' variable.
The attached patch binds the variable in the lexical environment.
It's a matter of whether or not this is the right thing to do.
Thoughts?


Emacs  : GNU Emacs 28.0.50 (build 1, x86_64-pc-linux-gnu, X 
toolkit, cairo version 1.17.4, Xaw3d scroll bars)
 of 2021-09-04
Package: Org mode version 9.4.6 (9.4.6-ga451f9 @ 
/home/n/.emacs.d/straight/build/org/)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: org-babel-execute-bind-lexical-binding-var --]
[-- Type: text/x-patch, Size: 1520 bytes --]

From 42b92303faa86b1e9bd0692fca9469eb6a8f02ce Mon Sep 17 00:00:00 2001
From: Nicholas Vollmer <iarchivedmywholelife@gmail.com>
Date: Thu, 9 Sep 2021 16:40:02 -0400
Subject: [PATCH] ob-emacs-lisp: bind lexical-binding for :lexical t src blocks

* lisp/ob-emacs-lisp.el (org-babel-execute:emacs-lisp): bind lexical-binding in lexical environments

Because we use `eval' to execute the src block, this variable needs to
be explicitly set. Passing t as eval's LEXICAL arg will not bind
this variable.
---
 lisp/ob-emacs-lisp.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el
index d03151f13..6cf387b96 100644
--- a/lisp/ob-emacs-lisp.el
+++ b/lisp/ob-emacs-lisp.el
@@ -61,7 +61,7 @@ by `org-edit-src-code'.")
 
 (defun org-babel-execute:emacs-lisp (body params)
   "Execute a block of emacs-lisp code with Babel."
-  (let* ((lexical (cdr (assq :lexical params)))
+  (let* ((lexical (org-babel-emacs-lisp-lexical (cdr (assq :lexical params))))
 	 (result-params (cdr (assq :result-params params)))
 	 (body (format (if (member "output" result-params)
 			   "(with-output-to-string %s\n)"
@@ -71,7 +71,7 @@ by `org-edit-src-code'.")
 				     (member "pp" result-params))
 				 (concat "(pp " body ")")
 			       body))
-		       (org-babel-emacs-lisp-lexical lexical))))
+		       (when lexical (list (cons 'lexical-binding t) t)))))
     (org-babel-result-cond result-params
       (let ((print-level nil)
             (print-length nil))
-- 
2.33.0


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

end of thread, other threads:[~2021-09-10 15:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-09 22:58 [BUG?][PATCH] Should the `lexical-binding' variable be bound during src block with :lexical t? [9.4.6 (9.4.6-ga451f9 @ /home/n/.emacs.d/straight/build/org/)] No Wayman
2021-09-10  1:53 ` Tim Cross
2021-09-10  2:38   ` No Wayman
2021-09-10  6:32 ` Timothy
2021-09-10 15:12   ` No Wayman
2021-09-10 15:15     ` No Wayman

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

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).