From 1d33039dde45651540cb19ea73f770bab96ac965 Mon Sep 17 00:00:00 2001 From: Daniel Borchmann Date: Mon, 17 Jul 2023 20:14:09 +0200 Subject: [PATCH] Unfold subtree before evaluating all source blocks This is meant to mitigate an issue with table alignment when those tables are results of source blocks, contain links in cells and are hidden (i.e., folded): in those circumstances, the table alignment seems to be broken, because the cell width does not take into account that links are shorter than their textual representation. I am not quite sure whether this is a bug in my configuration or a bug in Org mode itself. The function to compute cell width is `org-string-width`, but maybe this function does not get passed the correct input when tables are folded and need to be aligned? --- site-lisp/db-org.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/site-lisp/db-org.el b/site-lisp/db-org.el index f16cc24..eee5c57 100644 --- a/site-lisp/db-org.el +++ b/site-lisp/db-org.el @@ -861,8 +861,15 @@ With given ARG, force reevaluation as described for (interactive) (unless (derived-mode-p 'org-mode) (user-error "Not in Org buffer, aborting")) - (let ((org-confirm-babel-evaluate nil)) - (org-babel-execute-subtree arg))) + + ;; Since Org 9.6, we expand all folding before evaluating the current subtree, + ;; because `org-string-width' (called by `org-table-align') sometimes computes + ;; the wrong cell width in tables if those contain links. Is this a bug in + ;; Org mode? Maybe the input to `org-string-width' is not correct? + (org-fold-core-save-visibility :use-markers + (org-fold-show-all) + (let ((org-confirm-babel-evaluate nil)) + (org-babel-execute-subtree arg)))) ;;; Custom link handlers