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 yOwuCF65PmOwKQEAbAwnHQ (envelope-from ) for ; Thu, 06 Oct 2022 13:17:50 +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 kFlPCF65PmPGYQAA9RJhRA (envelope-from ) for ; Thu, 06 Oct 2022 13:17:50 +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 77F8C291A6 for ; Thu, 6 Oct 2022 13:17:48 +0200 (CEST) Received: from localhost ([::1]:45408 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogOss-0000uG-R6 for larch@yhetil.org; Thu, 06 Oct 2022 07:17:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55796) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogOmk-0005p8-M0 for emacs-orgmode@gnu.org; Thu, 06 Oct 2022 07:11:27 -0400 Received: from mail.hostpark.net ([212.243.197.30]:38228) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogOmi-0005BK-Ei for emacs-orgmode@gnu.org; Thu, 06 Oct 2022 07:11:26 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id F0FD5165FF for ; Thu, 6 Oct 2022 13:11:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=sel2011a; t=1665054677; bh=Pw4CYbOEKHPhOmE BOkeNAQbkW2iqAZ7WMhRoSX+7MOo=; b=YjyJJ8udbkSq3ZmlWhMuDHdwRw7v1xZ nPSc5FnWuG7d9Wx/+5HTKOQZse10pC4kv7LRG4q6oPQIxgd+IWqb0X4J+Rw6jjSG Q3UNaKvqTeEDM4C1K0S69w+44NDwsp2a1mpJuI8pI5lFaOT7mcfQaB1mfRl3WGf9 f0GEVI9WPj/k= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail0.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id gn9EE1bfUcRb for ; Thu, 6 Oct 2022 13:11:17 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id 07071165A6 for ; Thu, 6 Oct 2022 13:11:10 +0200 (CEST) From: Jonas Bernoulli To: emacs-orgmode@gnu.org Subject: [PATCH v1] Allow returning empty list from post-processing block Date: Thu, 6 Oct 2022 13:11:06 +0200 Message-Id: <20221006111106.22089-1-jonas@bernoul.li> X-Mailer: git-send-email 2.37.3 In-Reply-To: <875ygx7id9.fsf@localhost> References: <875ygx7id9.fsf@localhost> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: none client-ip=212.243.197.30; envelope-from=jonas@bernoul.li; helo=mail.hostpark.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 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-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1665055069; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=yzim+b4uo6WC0/r960P4x0OhOxkCdexVpLPG5Zykl3U=; b=dMaaID4dyAoXsAomQPYHRrEMUxx49nN20RTWpEwatG82k2E1LP2piaUm007hZ5NxrvFB66 2r+9TAYCGx3SpLWWWoCeJJr3EHd2uyOw7M0XT7XKGGgKSBKaX8bGbMGWScVO8nG2YJWV70 3Ig1z5HSYs/nyf0dCrmD16cP5HB0Yoq78EjrCkRVmyPLi6knS4zKJLI99RbpMlEgnCE4aO KRzj9ebQWl6Uc3sAZW0DmnEQr+nmO6P9qsM9gmyhTQ1gt58XYEj5DVbdrPeJdcT3NWwXMi Ps0LtxvBPmaJKwE6iFF0DVMmVxO63ajVwTg/nD3Fc3SN4aUlYkETTINygY2+8A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1665055069; a=rsa-sha256; cv=none; b=Qc3To8YtNIoeVqk1Y9WsGmpDFjpYUxFahbfUhhm0qPfFwBlCNg+NkH98ZJgjLwt7BVcgZ9 kQVW6dYxIaEPHVMldXMNAFknIF285ziQJ6UwUDkxHkWFxC2sxALpGI/pwbcnwnip0N2jsE Umc+Yb4orTcTihHK7410+anXNwUPJ28PrPflmsqbMxvJDAmltun+ljRyuR6Es6aUB0uo7B AYWRJagJC9ZXVAISkIkGGDU2eQ4o52B3S/mtap7JmCcM2Axg8RWi6E6eM3nxKHekZ1k6JQ tYigjIMfr5mgiYqTJIBnAOShK7FaqepKsSCAr70SVSH4J0ZvbqCTDGOcJB6KNQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=bernoul.li header.s=sel2011a header.b=YjyJJ8ud; dmarc=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: -0.47 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=bernoul.li header.s=sel2011a header.b=YjyJJ8ud; dmarc=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: 77F8C291A6 X-Spam-Score: -0.47 X-Migadu-Scanner: scn1.migadu.com X-TUID: GrhK0KjWaF+2 * lisp/ob-ref.el (org-babel-ref-resolve): When the result an empty list, then treat it as a list, not as the symbol nil. * testing/lisp/test-ob.el (test-ob/post-header-arguments): Add new test. * etc/ORG-NEWS (Post-processing code blocks can return an empty list): Document change in behavior. --- etc/ORG-NEWS | 6 ++++++ lisp/ob-ref.el | 2 +- testing/lisp/test-ob.el | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 4728528f8..74095d101 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -425,6 +425,12 @@ The new variable name is =org-plantuml-args=. It now applies to both jar PlantUML file and executable. ** Miscellaneous +*** Post-processing code blocks can return an empty list + +When the result of a regular code block is nil, then that was already +treated as an empty list. Now that is also the case for code blocks +that post-process the result of another block. + *** Styles are customizable in ~biblatex~ citation processor It is now possible to add new styles or modify old ones in ~biblatex~ diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index b79e47900..2b4a16aea 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -199,7 +199,7 @@ (defun org-babel-ref-resolve (ref) (org-babel-execute-src-block nil info params)))) (error "Reference `%s' not found in this buffer" ref)))) (cond - ((symbolp result) (format "%S" result)) + ((and result (symbolp result)) (format "%S" result)) ((and index (listp result)) (org-babel-ref-index-list index result)) (t result))))))))) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 99912fe63..9051a642d 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -136,6 +136,30 @@ (ert-deftest test-ob/get-src-block-info-tangle () (let ((info (org-babel-get-src-block-info))) (should (string= "no" (cdr (assq :tangle (nth 2 info)))))))) +(ert-deftest test-ob/post-header-arguments () + "When the result of a post-processing source block is an empty +list, then it should be treated as such; not as the symbol nil." + (should + (let ((default-directory temporary-file-directory)) + (org-test-with-temp-text + " +#+name: addheader +#+header: :var rows=\"\" +#+begin_src elisp :hlines yes + '() +#+end_src +#+header: :post addheader(*this*) +#+begin_src emacs-lisp :results table +#+end_src +#+RESULTS: +: nil" + (org-babel-execute-src-block) + (goto-char (1- (point-max))) + (equal (buffer-substring-no-properties + (line-beginning-position) + (line-end-position)) + "#+RESULTS:"))))) + (ert-deftest test-ob/elisp-in-header-arguments () "Test execution of elisp forms in header arguments." (org-test-with-temp-text-in-file " -- 2.37.3