Skip to content

Commit 9b69046

Browse files
tarsiusyantar92
authored andcommitted
Allow returning empty list from post-processing block
* 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.
1 parent eece396 commit 9b69046

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

etc/ORG-NEWS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,12 @@ The new variable name is =org-plantuml-args=. It now applies to both
425425
jar PlantUML file and executable.
426426

427427
** Miscellaneous
428+
*** Post-processing code blocks can return an empty list
429+
430+
When the result of a regular code block is nil, then that was already
431+
treated as an empty list. Now that is also the case for code blocks
432+
that post-process the result of another block.
433+
428434
*** Styles are customizable in ~biblatex~ citation processor
429435

430436
It is now possible to add new styles or modify old ones in ~biblatex~

lisp/ob-ref.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Emacs Lisp representation of the value of the variable."
199199
(org-babel-execute-src-block nil info params))))
200200
(error "Reference `%s' not found in this buffer" ref))))
201201
(cond
202-
((symbolp result) (format "%S" result))
202+
((and result (symbolp result)) (format "%S" result))
203203
((and index (listp result))
204204
(org-babel-ref-index-list index result))
205205
(t result)))))))))

testing/lisp/test-ob.el

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,30 @@ should still return the link."
136136
(let ((info (org-babel-get-src-block-info)))
137137
(should (string= "no" (cdr (assq :tangle (nth 2 info))))))))
138138

139+
(ert-deftest test-ob/post-header-arguments ()
140+
"When the result of a post-processing source block is an empty
141+
list, then it should be treated as such; not as the symbol nil."
142+
(should
143+
(let ((default-directory temporary-file-directory))
144+
(org-test-with-temp-text
145+
"
146+
#+name: addheader
147+
#+header: :var rows=\"\"
148+
#+begin_src elisp :hlines yes
149+
'()
150+
#+end_src
151+
#+header: :post addheader(*this*)
152+
#+<point>begin_src emacs-lisp :results table
153+
#+end_src
154+
#+RESULTS:
155+
: nil"
156+
(org-babel-execute-src-block)
157+
(goto-char (1- (point-max)))
158+
(equal (buffer-substring-no-properties
159+
(line-beginning-position)
160+
(line-end-position))
161+
"#+RESULTS:")))))
162+
139163
(ert-deftest test-ob/elisp-in-header-arguments ()
140164
"Test execution of elisp forms in header arguments."
141165
(org-test-with-temp-text-in-file "

0 commit comments

Comments
 (0)