From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id wM7RHDKGPWODeAAAbAwnHQ (envelope-from ) for ; Wed, 05 Oct 2022 15:27:14 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id yJfZGzKGPWPnqQAAG6o9tA (envelope-from ) for ; Wed, 05 Oct 2022 15:27:14 +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 ECB9DC88F for ; Wed, 5 Oct 2022 15:27:13 +0200 (CEST) Received: from localhost ([::1]:44786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1og4Qa-0005qk-VU for larch@yhetil.org; Wed, 05 Oct 2022 09:27:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1og4L9-0005gY-B0 for emacs-orgmode@gnu.org; Wed, 05 Oct 2022 09:21:46 -0400 Received: from mail.hostpark.net ([212.243.197.30]:47118) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1og4L6-00019r-At for emacs-orgmode@gnu.org; Wed, 05 Oct 2022 09:21:35 -0400 Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 1E0AE162BF for ; Wed, 5 Oct 2022 15:21:26 +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=1664976085; bh=zSsT2hyFYcY9+j1 OiyBBV1TcyIjoZ6naCjC0ok7ywNM=; b=OOFULtUIUx0JdsAzosKk/StuVmLpWbN k+rvq7vtLSjXz/wIJLY74yabwCDlgo071pFncU3f5vS1IDEO7KryNX4mVicJ3vS8 eRaYFFNM/ft7uYZ7KPFS7i8k+FBhRl5fBwf95LxUmrtY+sMl2jN2EAZIj0txX+Cw H+ZuHQJDRVD4= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail1.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id E5DV8NnudDTw for ; Wed, 5 Oct 2022 15:21:25 +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 E7C5A16483 for ; Wed, 5 Oct 2022 15:21:25 +0200 (CEST) From: Jonas Bernoulli To: emacs-orgmode@gnu.org Subject: [PATCH 1/1] Allow returning empty list from post-processing block Date: Wed, 5 Oct 2022 15:21:22 +0200 Message-Id: <20221005132122.19212-2-jonas@bernoul.li> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221005132122.19212-1-jonas@bernoul.li> References: <874jwkwb4c.fsf@localhost> <20221005132122.19212-1-jonas@bernoul.li> 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=1664976434; 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=wvlTliJcGwDLo3sRJwvezhNDbdGGGE2pqoF6xtskJo4=; b=QaO0J6YdDAGQrNT047kPnhea3pQ0zkaZr372izz60Fn0YPes0EG+gQR/MhGfozfEAfkL/9 g/RVX/iTO1VY7tmhEa8siS0Fjfb2hISOAHY4A2b0v6uT3bkEp5RUlT3sZsm7ti5ZxUslJ3 mj0YlDljSSeJnkvHPVTiQ3z0dqWeW74MdxwNxKMyP6QYsAvDLnN5OWAhyVKVFMcW8VeaKE dE+FL2tHudgWAh3EzFPjioHLhAR2NFIPPbmm70D057wB58U/Sj76bxhVAmbtZ3wGyOpANX /53vfYrZgA5egj5YROZO+E3nU2x/LK58O1c4I/xbyaW6Z5xDj2m4TS190D0+Fw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1664976434; a=rsa-sha256; cv=none; b=S6j0JZAuF5txj1qOUbD5koVcLi+piR/6tbzLzlCSvzbR69OccJ6q9/LFwLI7DzJhkvmbSg p7kk9wSxVcvcpxhLU4N0Vgp7s99VkGouO2gD2A9AXoTl2YAR62i7ShBFsJeSqnC2bY4ALf 82eqqkeSzcwWyfSnzq8J4LMcZZYtLpgeo5YZLsUMwLsQI9gfG5SpgAwvVjhA7nlJ218TKY vWR7uLOdC8Xez/FCDAHYzfyVH7ejmKenUi0dyusBrjIF87PYRACkTgaehEP6u40YMZVCZi OKTo1WaHC5u6CCERxnYScdF2WrAFiSrOxXY2Gbcqf+mCUyyXa/sRw/nKFFVFCg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=bernoul.li header.s=sel2011a header.b=OOFULtUI; 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: -1.96 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=bernoul.li header.s=sel2011a header.b=OOFULtUI; 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: ECB9DC88F X-Spam-Score: -1.96 X-Migadu-Scanner: scn0.migadu.com X-TUID: tMjtcxLsjerI * 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/return-empty-list-from-post-block): 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..8d1548fe1 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -26,6 +26,30 @@ (require 'ob-ref) (require 'org-table) (eval-and-compile (require 'cl-lib)) +(ert-deftest test-ob/return-empty-list-from-post-block () + "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/indented-cached-org-bracket-link () "When the result of a source block is a cached indented link it should still return the link." -- 2.37.3