emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix behavior of lambda default header arg vars
@ 2021-10-27 14:57 Matt Huszagh
       [not found] ` <87y252bfr4.fsf@gmail.com>
  2022-06-05 12:18 ` Ihor Radchenko
  0 siblings, 2 replies; 9+ messages in thread
From: Matt Huszagh @ 2021-10-27 14:57 UTC (permalink / raw)
  To: emacs-orgmode

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

Hello,

:var header arguments can be provided multiple times. This is supported
directly at the source block and through the default header argument
facility. However, this was not handled correctly when the var was
evaluated from a closure in a default header argument (only the last var
was taken). This patch fixes that. I've also added documentation
explaining how to set multiple vars in the default header argument
facility.

Thanks,
Matt


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-core.el-Fix-behavior-of-lambda-default-header-arg.patch --]
[-- Type: text/x-patch, Size: 2668 bytes --]

From 5f02fe4e896e6909fab18e8d90a7e14bdce9d5c4 Mon Sep 17 00:00:00 2001
From: Matt Huszagh <huszaghmatt@gmail.com>
Date: Wed, 27 Oct 2021 07:47:20 -0700
Subject: [PATCH] ob-core.el: Fix behavior of lambda default header arg vars

* lisp/ob-core.el: Permit multiple :var default header arguments when
using closures. Additionally, document how to use default header
arguments for arguments that can be provided multiple times.
---
 lisp/ob-core.el | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 7a9467b0e..21f461a08 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -478,12 +478,21 @@ 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.  Some header arguments (e.g., :var for
+some language backends) can be provided multiple times for a
+source block.  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\\\"\"))
+
+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
@@ -2718,6 +2727,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


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

end of thread, other threads:[~2022-07-09  5:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-27 14:57 [PATCH] Fix behavior of lambda default header arg vars Matt Huszagh
     [not found] ` <87y252bfr4.fsf@gmail.com>
2021-12-03  2:43   ` Matt Huszagh
2022-06-05 12:18 ` Ihor Radchenko
2022-06-05 16:00   ` Matt Huszagh
2022-06-11  2:47     ` Ihor Radchenko
2022-06-28  3:53       ` Matt Huszagh
2022-06-29 10:02         ` Ihor Radchenko
2022-07-08 23:12           ` Matt Huszagh
2022-07-09  5:23             ` Ihor Radchenko

Code repositories for project(s) associated with this public 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).