emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: No Wayman <iarchivedmywholelife@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [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/)]
Date: Thu, 09 Sep 2021 18:58:23 -0400	[thread overview]
Message-ID: <87tuit73ij.fsf@gmail.com> (raw)

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

I ran into this with some code I'm writing which checks against 
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" 

Currently the `lexical-binding' variable is not bound because 
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.

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 @ 

[-- 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 ")")
-		       (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))

             reply	other threads:[~2021-09-09 23:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-09 22:58 No Wayman [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuit73ij.fsf@gmail.com \
    --to=iarchivedmywholelife@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [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/)]' \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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


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