>> Does it make sense to add a configuration variable for printing the
>> results of blocks evaluated indirectly to fix this? It could have the
>> following values:
>> - nil (default): Don't print the results of blocks evaluated
>>   indirectly, as it's done now
>> - 'cache: do it only if the block has a cache header argument
>> - t: Do it always
>>
>> WDYT? I guess it should be relatively easy to do it with the pieces
>> that already exist, so if you agree it's a good idea I can try
>
> Sounds reasonable.
> +1

I took a look at the code and it's more convoluted than I expected. But
in the end I found out the reason why results are not printed for blocks
evaluated indirectly, it's this line:
https://github.com/emacsmirror/org/blob/8da0562b4d26cdac86fa4bbf830c531b2df41cd8/lisp/ob-ref.el#L164.
That parameter is later used in `org-babel-execute-src-block` to
determine whether the results should be printed or not. I decided to do
the change in that function, to localize the change as much as possible
and avoid any potential side effects of changing that parameter too
early. What I do is just ignoring that parameter is a block has the
header argument :cache yes. That comes at the price of not including the
variable I suggested, and always print results for blocks that have
:cache yes, but I think that always makes sense from a DWIM perspective,
and I can't think of any downside of it. I attached the patch, let me
know what you think.

>From eee9fd9ea49ee7b08284d2ed15f7116ea942457a Mon Sep 17 00:00:00 2001
From: Ignacio Casso <[email protected]>
Date: Sun, 8 Feb 2026 22:40:08 +0100
Subject: [PATCH] print result of cached blocks even if results are set to
 "none"

* lisp/ob-core.el (org-babel-execute-src-block): always print results
of a source block with :cache yes even if :results is "none". This
allows results to be cached also when the block is evaluated
indirectly as a dependency of another block

See https://list.orgmode.org/orgmode/[email protected]
---
 lisp/ob-core.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index a8ca1ccd0..75563c4a7 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -953,7 +953,7 @@ guess will be made."
 		    (setq result (org-babel-ref-resolve post))
 		    (when file
 		      (setq result-params (remove "file" result-params))))))
-	      (unless (member "none" result-params)
+	      (unless (and (not cache) (member "none" result-params))
 	        (org-babel-insert-result
 	         result result-params info
                  ;; append/prepend cannot handle hash as we accumulate
-- 
2.43.0

Reply via email to