CONFIRMED.

Here's a patch to fix it.

> Consider this code block:
>
> ,#+begin_src emacs-lisp :prologue "(setq foo t)"
> (if (and (boundp 'foo) foo)
> "foo is set"
> "foo is NOT set")
> ,#+end_src
>
> When run it produces:
>
> ,#+RESULTS:
> : foo is NOT set
>
> which is odd, because the prologue is supposed to set foo. Now try this
> one:
>
> ,#+begin_src emacs-lisp :prologue "(setq foo t)" :var dummy=()
> (if (and (boundp 'foo) foo)
> "foo is set"
> "foo is NOT set")
> ,#+end_src
>
> This time it produces "foo is set", which is what I expected to happen.
>
> I believe this is due to the following code in
> org-babel-expand-body:emacs-lisp
> (line 55 of ob-emacs-lisp.el):
>
> (if (null vars) body              ; no variables = no use of
> prologue/epilogue
> (format "(let (%s)\n%s%s%s\n)"
> ...

--
Paul
>From 7bd65c8cf1cab1f87fab977d62e36fdf7ee97a9f Mon Sep 17 00:00:00 2001
From: Paul Bryan <[email protected]>
Date: Sun, 8 Nov 2026 22:24:21 +1100
Subject: [PATCH] ob-emacs-lisp.el: Always expand pro/epi-logue in elisp src
 blocks

* ob-emacs-lisp.el (org-babel-expand-body): Expand prologue
and epilogue in elisp source blocks even when variable list
is null.

Reported-by: Jeff Trull <[email protected]>
Link: https://list.orgmode.org/CAF_DUeHQo4k2GK=_-2EEyJmePa0rHJMXVJY1nLgh=ogt+xs...@mail.gmail.com/
---
 lisp/ob-emacs-lisp.el | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-emacs-lisp.el b/lisp/ob-emacs-lisp.el
index 4738eba93..91a3d19a6 100644
--- a/lisp/ob-emacs-lisp.el
+++ b/lisp/ob-emacs-lisp.el
@@ -47,20 +47,22 @@ by `org-edit-src-code'.")
 
 (defun org-babel-expand-body:emacs-lisp (body params)
   "Expand BODY according to PARAMS, return the expanded body."
-  (let ((vars (org-babel--get-vars params))
+  (let* ((vars (org-babel--get-vars params))
 	(print-level nil)
 	(print-length nil)
         (prologue (cdr (assq :prologue params)))
-        (epilogue (cdr (assq :epilogue params))))
+        (epilogue (cdr (assq :epilogue params)))
+        (body (concat
+               (if prologue (concat prologue "\n      ") "")
+	       body
+               (if epilogue (concat "\n      " epilogue "\n") ""))))
     (if (null vars) body
-      (format "(let (%s)\n%s%s%s\n)"
+      (format "(let (%s)\n%s\n)"
 	      (mapconcat
 	       (lambda (var)
 		 (format "%S" `(,(car var) ',(cdr var))))
 	       vars "\n      ")
-              (if prologue (concat prologue "\n      ") "")
-	      body
-              (if epilogue (concat "\n      " epilogue "\n") "")))))
+              body))))
 
 (defun org-babel-execute:emacs-lisp (body params)
   "Execute emacs-lisp code BODY according to PARAMS."
-- 
2.56.0

Reply via email to