From: Jonas Bernoulli <jonas@bernoul.li>
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 [thread overview]
Message-ID: <20221005132122.19212-2-jonas@bernoul.li> (raw)
In-Reply-To: <20221005132122.19212-1-jonas@bernoul.li>
* 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*)
+#+<point>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
next prev parent reply other threads:[~2022-10-05 13:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-03 19:29 Post-process table without changing result for empty table(/list) Jonas Bernoulli
2022-10-04 2:55 ` Ihor Radchenko
2022-10-04 14:00 ` Jonas Bernoulli
2022-10-05 7:37 ` Ihor Radchenko
2022-10-05 13:21 ` [PATCH 0/1] Allow returning empty list from post-processing block Jonas Bernoulli
2022-10-05 13:21 ` Jonas Bernoulli [this message]
2022-10-06 3:15 ` [PATCH 1/1] " Ihor Radchenko
2022-10-06 11:11 ` [PATCH v1] " Jonas Bernoulli
2022-10-07 4:09 ` Ihor Radchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221005132122.19212-2-jonas@bernoul.li \
--to=jonas@bernoul.li \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).