Hi Ihor, Modifications made and split into two patches. Let me know if any remaining issues.
Thanks Matt
>From fdc6e103932c68b450c72d44d062b4746ec2202c Mon Sep 17 00:00:00 2001 From: Matt Huszagh <huszaghm...@gmail.com> Date: Mon, 27 Jun 2022 20:41:02 -0700 Subject: [PATCH 1/2] ob-core.el: Fix behavior of lambda default header arg vars * lisp/ob-core.el: Permit multiple :var default header arguments when using closures. --- lisp/ob-core.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 7a9467b0e..80086f12c 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2718,6 +2718,11 @@ parameters when merging lists." (pcase pair (`(:var . ,value) (let ((name (cond + ;; Default header arguments can accept lambda + ;; functions. We uniquely identify the var + ;; according to the full string contents of + ;; the lambda function. + ((functionp value) value) ((listp value) (car value)) ((string-match "^\\([^= \f\t\n\r\v]+\\)[ \t]*=" value) (intern (match-string 1 value))) -- 2.31.1
>From 7af7ad3990410ca388c841e045ec66ce694b404a Mon Sep 17 00:00:00 2001 From: Matt Huszagh <huszaghm...@gmail.com> Date: Mon, 27 Jun 2022 20:42:27 -0700 Subject: [PATCH 2/2] ob-core.el: Improve org-babel-default-header-args docstring * lisp/ob-core.el: Provide example illustrating one benefit of using closures as default header arguments. Additionally, explain how to provide the same type of header argument multiple times in the default alist. --- lisp/ob-core.el | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 80086f12c..6c3c79126 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -478,12 +478,14 @@ For the format of SAFE-LIST, see `org-babel-safe-header-args'." This is a list in which each element is an alist. Each key corresponds to a header argument, and each value to that header's value. The value can either be a string or a closure that -evaluates to a string. The closure is evaluated when the source -block is being evaluated (e.g. during execution or export), with -point at the source block. It is not possible to use an -arbitrary function symbol (e.g. 'some-func), since org uses -lexical binding. To achieve the same functionality, call the -function within a closure (e.g. (lambda () (some-func))). +evaluates to a string. + +A closure is evaluated when the source block is being +evaluated (e.g. during execution or export), with point at the +source block. It is not possible to use an arbitrary function +symbol (e.g. 'some-func), since org uses lexical binding. To +achieve the same functionality, call the function within a +closure (e.g. (lambda () (some-func))). To understand how closures can be used as default header arguments, imagine you'd like to set the file name output of a @@ -500,7 +502,16 @@ this with: Because the closure is evaluated with point at the source block, the call to `org-element-at-point' above will always retrieve -information about the current source block.") +information about the current source block. + +Some header arguments can be provided multiple times for a source +block. An example of such a header argument is :var. This +functionality is also supported for default header arguments by +providing the header argument multiple times in the alist. For +example: + +'((:var . \"foo=\\\"bar\\\"\") + (:var . \"bar=\\\"foo\\\"\"))") (put 'org-babel-default-header-args 'safe-local-variable (org-babel-header-args-safe-fn org-babel-safe-header-args)) -- 2.31.1