From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id 6I8jGW97umLSqwAAbAwnHQ (envelope-from ) for ; Tue, 28 Jun 2022 05:54:23 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id YO/7GG97umLLTAAA9RJhRA (envelope-from ) for ; Tue, 28 Jun 2022 05:54:23 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1B05E978C for ; Tue, 28 Jun 2022 05:54:23 +0200 (CEST) Received: from localhost ([::1]:35106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o62Iv-0000Lf-Lm for larch@yhetil.org; Mon, 27 Jun 2022 23:54:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o62IB-0000LS-3D for emacs-orgmode@gnu.org; Mon, 27 Jun 2022 23:53:35 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:41549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o62I9-0008Gr-CT for emacs-orgmode@gnu.org; Mon, 27 Jun 2022 23:53:34 -0400 Received: by mail-pf1-x435.google.com with SMTP id i64so10830666pfc.8 for ; Mon, 27 Jun 2022 20:53:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=1Xc+TxaClCUBuQL79kRHRvdV3KgjJuqLT7chRVtEHCA=; b=MYtL6I+F4OTj0bMOgjjMu5wdajkaoC+hEO+/ei1gh0fsWrYFgSRwjD6TUNutkPq7eN 5XWW4yXwcbpdYiznACJP0zkjBbkmqyQsINEuvXfdoHPMbOGq9ewD/P1cDqS39h3tDyWh 1FL6Rh3p6vxJhI3Q87rCDY2wVFy6nI6EoOC2qwICYplSunW2ebb0OjYpn3rS1podvfib DsMP1sne9OYjw8WWGy8ar/Ox81F4iDJK7SUYzLXe0sOZ54X02Pid2oMFKb8c3hlnRicd JPFHBam/C/bcydiPQhuwRKcaLkE5hn8bR24Uay2S8dSYw504f1SFiDcV11OeycXcuBKm /o5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:cc:subject:in-reply-to:references :date:message-id:mime-version; bh=1Xc+TxaClCUBuQL79kRHRvdV3KgjJuqLT7chRVtEHCA=; b=z0CWKgdqJ3zuuH0qQTJYm7V1Kxno3+7pNJbv3RSidcZMYlqzXAp3RzMgkon9VcCjh5 BeJX4fjBQ8DtsWXI6FyoavOyiTXfWQ1pzBR97RWzTr+L4K+m1AsHR/X8zE3Z4Xt09wyZ /JRdsgQsgMEjsG2cr8WQhjWJkGxPfgSKiAMsueUJsP/NnoI0clFaJ8hYJakdgVCIJiji +N7MTugVlWSTAG4aS7WB26GNkvuBrR5cPpKpnivxQYVe/XZlOS3fHQMW3RRrBJdibSk2 2h1VKkTTFF0zHjNPkwsW3W/QDtqzmDADU9J/KcD3ECylZXf9khKTXf2vBRr2XUOOTgUv gmow== X-Gm-Message-State: AJIora+ilQeT/SI7Zc3IVaMrQefAAMx+iWw+kqk8fqv08Bd6jpzcMYK7 iWkOlinr98xm4C/FK9ZuoWEw1TaD74c= X-Google-Smtp-Source: AGRyM1vtVyK3SM+TojrcbWltT7GJvqLW5Lkpae5aXSH/eeG1zb1909ZUNcO1m2qaFYtjdg75W/XxBg== X-Received: by 2002:a05:6a02:11b:b0:40d:dfdc:95d7 with SMTP id bg27-20020a056a02011b00b0040ddfdc95d7mr9861952pgb.536.1656388410162; Mon, 27 Jun 2022 20:53:30 -0700 (PDT) Received: from ryzen3950 (c-208-82-98-189.rev.sailinternet.net. [208.82.98.189]) by smtp.gmail.com with ESMTPSA id y22-20020a17090264d600b0016a0b31a8bdsm8094893pli.4.2022.06.27.20.53.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 20:53:28 -0700 (PDT) From: Matt Huszagh To: Ihor Radchenko Cc: "emacs-orgmode@gnu.org" Cc: Subject: Re: [PATCH] Fix behavior of lambda default header arg vars In-Reply-To: <87wndnq5kw.fsf@localhost> References: <87o87abjm5.fsf@gmail.com> <87ee035mnp.fsf@localhost> <87ee03je2m.fsf@gmail.com> <87wndnq5kw.fsf@localhost> Date: Mon, 27 Jun 2022 20:53:28 -0700 Message-ID: <8735fpv3yf.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=huszaghmatt@gmail.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1656388463; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=1Xc+TxaClCUBuQL79kRHRvdV3KgjJuqLT7chRVtEHCA=; b=ovG4AUIqaYoxIgYPNYt40X/8XWqliplhhRGBzz6YwC4d3weI9UngkV/3Uy7+hjtlcBsXoI oaIpTjHQ7EvSfMr5mU6MauLKHN9L+K1PjrIpySKwCtc/0q3OB/0PNu5FGaxmZQ86FYzqR0 lp5ji1+9+hLEP0KeSe6/zfPhYFiMdzPqf55DL2NC1XIT3ABFHeBOW8baqqCTBq9ownEJSb G84XaJVhOCVeOcuDQG56pcXpxwSq9LfhuwIFgJ/pFUCYouSpn6D3MPu5Sziw6cqsmStVCv L+FMK3j35at3NFzsewYceSNhfd2HIJmYdXSFA/sbV3psU3gd4+4AEidqoMbFVg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1656388463; a=rsa-sha256; cv=none; b=VHqdF2RsxdLRajZ1pJ4SnyymsxHINti1cE3JZrWHvmhL0g1gOxH6VMzVb9j6zU1WHIAsXz pTLcadLNjff3amxdC8pix7m04OM+wkqS4gn9pjHS15ksgC0g/oR28MiGUKpIHcqR8nZetN 2hjpaUYffY/KTb6KQSZPGm35oLe/Cke+7avtnzVK0qZ8O2i/0Bij7GXMJc4fY4SXmzWBK7 t4/6sR8uqu8ijvW5sZ/BqjiZ0sYjqCPmvOMUpM0dlG3PIEFnSRnWlkO2nipKnbjE24hVQb PcbURmPOuJDpFJUkq45R/MCRBGOsldlG0p9HoMfruGJvVfCMHwqOmDbt9mB73w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=MYtL6I+F; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: 8.45 X-Spam: Yes Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20210112 header.b=MYtL6I+F; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 1B05E978C X-Spam-Score: 8.45 X-Migadu-Spam: Yes X-Migadu-Scanner: scn1.migadu.com X-TUID: g5XOGZ2k0lJX --=-=-= Content-Type: text/plain Hi Ihor, Modifications made and split into two patches. Let me know if any remaining issues. Thanks Matt --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-core.el-Fix-behavior-of-lambda-default-header-arg.patch >From fdc6e103932c68b450c72d44d062b4746ec2202c Mon Sep 17 00:00:00 2001 From: Matt Huszagh 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-ob-core.el-Improve-org-babel-default-header-args-doc.patch >From 7af7ad3990410ca388c841e045ec66ce694b404a Mon Sep 17 00:00:00 2001 From: Matt Huszagh 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 --=-=-=--