org-mode-var-header-args-expansion.org 1.2 KB

Redefine/override org-babel-expand-body:scheme to avoid let-wrapping with :var header args in source blocks.

(defun xiaolong/org-babel-format-vars (vars) "Format :var header arguments given as VARS." (mapconcat (lambda (var) (format "(define %s %S)" (car var) (cdr var))) vars "\n"))

(eval-after-load "org" '(defun org-babel-expand-body:scheme (body params) "Expand BODY according to PARAMS, return the expanded body." (let ((vars (org-babel--get-vars params)) (prepends (cdr (assq :prologue params))) (postpends (cdr (assq :epilogue params)))) (concat (and prepends (concat prepends "\n")) (if (null vars) body (concat (xiaolong/org-babel-format-vars vars) body)) (and postpends (concat "\n" postpends))))))

For more background see the following mailing list thread: https://lists.gnu.org/archive/html/emacs-orgmode/2023-03/msg00087.html. The code above is my personal solution to the problem, posted also on the mailing list: https://lists.gnu.org/archive/html/emacs-orgmode/2023-03/msg00163.html.