But in the process, I seem to have stumbled upon a bug.. the buffer local value of variables are not respected at the time of exports.
To demonstrate that, please evaluate the elisp code at the end of this email and do C-c C-e h o on the below MWE of org file:
;; Recalculate all org tables in the buffer when saving.
(defvar-local modi/org-table-enable-buffer-wide-recalculation t
"When non-nil, all the org tables in the buffer will be recalculated when
saving the file or when exporting.
This variable is buffer local.")
;; Mark `modi/org-table-enable-buffer-wide-recalculation' as a safe local
;; variable as long as its value is t or nil. That way you are not prompted
;; to add that to `safe-local-variable-values' in custom.el.
'safe-local-variable (lambda (val) (or (equal val nil) (equal val t))))
(defun modi/org-table-recalculate-buffer-tables (&rest args)
"Wrapper function for `org-table-recalculate-buffer-tables' that runs
that function only if `modi/org-table-enable-buffer-wide-recalculation' is
Also, this function has ARGS as optional arguments that are needed for any
function that is added to the `org-export-before-processing-hook'."
(message "modi/org-table-enable-buffer-wide-recalculation: %S"
(defun modi/org-table-recalculate-before-save ()
"Recalculate all org tables in the buffer before saving."
(add-hook 'before-save-hook #'modi/org-table-recalculate-buffer-tables nil :local))
(add-hook 'org-mode-hook #'modi/org-table-recalculate-before-save)
;; FIXME: The buffer local value of `modi/org-table-enable-buffer-wide-recalculation'
;; does not seem to be respected at the moment at the time of running
;; `org-export-before-processing-hook'. Investigating this ..
;; For now, as the default value of that variable is t, all org tables
;; in the buffer will always be recalculated at the time of export even
;; if the buffer local value of that var is nil.
(add-hook 'org-export-before-processing-hook #'modi/org-table-recalculate-buffer-tables)