Done all of them, I attach the updated patch. Just one question for the next time, how should I know that the next version is 10.0 and not 9.9 without you telling me?
>> +(defcustom org-babel-update-intermediate nil >> + "Update the in-buffer results of code blocks executed to resolve >> references. > When non-nil, update ... Line was too long, so I came up with a different alternative, let me know what you think
>From 3c835060d189b7f6f0606047a1b6eb4f0033849b Mon Sep 17 00:00:00 2001 From: Ignacio Casso <[email protected]> Date: Mon, 9 Mar 2026 20:02:39 +0100 Subject: [PATCH] org-babel: Fix and extend `org-babel-update-intermediate' variable * lisp/ob-core.el (org-babel-update-intermediate): Move variable to ob-core.el, make it custom, and add `cached' as new possible value to only update intermediate blocks when they have the :cache yes header argument. * lisp/ob-ref.el (org-babel-ref-resolve): Fix usage of `org-babel-update-intermediate' so that it only affects the :results "none" header argument (before it was also affecting other header arguments like parameter values, which resulted in a bug). * lisp/ob-core.el (org-babel-execute-src-block): Use the cache header argument and `org-babel-update-intermediate' to decide whether :results "none" header argument should be ignored. This allows results of cached blocks to be actually cached also when the block is evaluated indirectly as a dependency of another block. Link: https://list.orgmode.org/orgmode/[email protected] --- etc/ORG-NEWS | 8 ++++++++ lisp/ob-core.el | 20 +++++++++++++++++++- lisp/ob-ref.el | 14 ++++++-------- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index 985b4b6d7..fd948e5a0 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -107,6 +107,14 @@ can be also written as: ,#+LATEX_CLASS_OPTIONS: a4paper,12pt #+END_SRC +*** Updated custom variable ~org-babel-update-intermediate~ + +The variable is now a custom variable, a minor bug with it is fixed, +and it can take a new value: `cached'. In that case, only the +intermediate blocks with :cache yes header argument will be +updated. This allows for the cache feature to still work when a block +is evaluated indirectly to resolve a reference in another block. + ** New functions and changes in function arguments # This also includes changes in function behavior from Elisp perspective. diff --git a/lisp/ob-core.el b/lisp/ob-core.el index a8ca1ccd0..14031b7aa 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -953,7 +953,9 @@ 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 (member "none" result-params) + (not (and cache + (eq 'cached org-babel-update-intermediate)))) (org-babel-insert-result result result-params info ;; append/prepend cannot handle hash as we accumulate @@ -3554,6 +3556,22 @@ Emacs shutdown.") :group 'org-babel :type 'string) +(defcustom org-babel-update-intermediate nil + "Whether to update in-buffer results of blocks executed to resolve references. + +If value is nil, they will never be updated. If value is non-nil, they +will always be updated. A value of `cached' means to only update them if +the block has the cache header argument set to yes. This is needed +for the cache feature to work properly, as it relies on source block +results being printed in the Org buffer." + :group 'org-babel + :package-version '(Org . "10.0") + :type '(choice + (const :tag "Never update intermediate results" nil) + (const :tag "Always update intermediate results" t) + (const :tag "Update results only if they should be cached" cache))) + + (defmacro org-babel-result-cond (result-params scalar-form &rest table-forms) "Call the code to parse raw string results according to RESULT-PARAMS. Do nothing with :results discard. diff --git a/lisp/ob-ref.el b/lisp/ob-ref.el index 14c5ce4a9..8ce1332ba 100644 --- a/lisp/ob-ref.el +++ b/lisp/ob-ref.el @@ -70,9 +70,6 @@ (declare-function org-narrow-to-subtree "org" (&optional element)) (declare-function org-fold-show-context "org-fold" (&optional key)) -(defvar org-babel-update-intermediate nil - "Update the in-buffer results of code blocks executed to resolve references.") - (defun org-babel-ref-parse (assignment) "Parse a variable ASSIGNMENT in a header argument. @@ -161,7 +158,10 @@ Emacs Lisp representation of the value of the variable." (setq ref split-ref))) (org-with-wide-buffer (goto-char (point-min)) - (let* ((params (append args '((:results . "none")))) + (let* ((params (if (and org-babel-update-intermediate + (not (eq 'cached org-babel-update-intermediate))) + args + (append args '((:results . "none"))))) (regexp (org-babel-named-data-regexp-for-name ref)) (result (catch :found @@ -183,9 +183,7 @@ Emacs Lisp representation of the value of the variable." (throw :found (org-babel-execute-src-block nil nil - (and - (not org-babel-update-intermediate) - params)))) + params))) ((and (let v (org-babel-read-element e)) (guard v)) (throw :found v)) @@ -198,7 +196,7 @@ Emacs Lisp representation of the value of the variable." org-babel-library-of-babel)))) (when info (throw :found - (org-babel-execute-src-block nil info params)))) + (org-babel-execute-src-block nil info (append args '((:results . "none"))))))) (error "Reference `%s' not found in this buffer" ref)))) (cond ((and result (symbolp result)) (format "%S" result)) -- 2.43.0
