From 25869e5670942f069cd3b4c3612610711fd28cca Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Sun, 31 Mar 2013 18:47:44 -0400 Subject: [PATCH] Add 'inline-only option to org-export-babel-evaluate * lisp/ob-exp.el (org-export-babel-evaluate): Add a 'inline-only option. (org-babel-exp-results): Implement 'inline-only for `org-export-babel-evaluate'. * doc/org.texi (Exporting code blocks): Document the 'inline-only setting for `org-export-babel-evaluate'. This is useful because there is no way for inline results to be stored. The imagined usecase is that all non-inline source blocks will be evaluated manually by the user. Inline blocks, however, must be evaluated during export, or they will be simply deleted by the exporter. --- doc/org.texi | 7 ++++++- lisp/ob-exp.el | 11 ++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index 8d54d1ba5..07c671fd6 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -13582,7 +13582,12 @@ Setting the @var{org-export-babel-evaluate} variable to @code{nil} will ensure that no code blocks are evaluated as part of the export process. This can be useful in situations where potentially untrusted Org mode files are exported in an automated fashion, for example when Org mode is used as the -markup language for a wiki. +markup language for a wiki. It is also possible to set this variable to +@code{‘inline-only}. In that case, only inline code blocks will be +evaluated, in order to insert their results. Non-inline code blocks are +assumed to have their results already inserted in the buffer by manual +evaluation. This setting is useful to avoid expensive recalculations during +export, not to provide security. @comment node-name, next, previous, up @comment Extracting source code, Evaluating code blocks, Exporting code blocks, Working With Source Code diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el index 664a52b0c..d9fb294b2 100644 --- a/lisp/ob-exp.el +++ b/lisp/ob-exp.el @@ -52,10 +52,13 @@ (defcustom org-export-babel-evaluate t "Switch controlling code evaluation during export. When set to nil no code will be evaluated as part of the export -process." +process. When set to 'inline-only, only inline code blocks will +be executed." :group 'org-babel :version "24.1" - :type 'boolean) + :type '(choice (const :tag "Never" nil) + (const :tag "Only inline code" inline-only) + (const :tag "Always" t))) (put 'org-export-babel-evaluate 'safe-local-variable (lambda (x) (eq x nil))) (defun org-babel-exp-get-export-buffer () @@ -378,7 +381,9 @@ Results are prepared in a manner suitable for export by org-mode. This function is called by `org-babel-exp-do-export'. The code block will be evaluated. Optional argument SILENT can be used to inhibit insertion of results into the buffer." - (when (and org-export-babel-evaluate + (when (and (or (eq org-export-babel-evaluate t) + (and (eq type 'inline) + (eq org-export-babel-evaluate 'inline-only))) (not (and hash (equal hash (org-babel-current-result-hash))))) (let ((lang (nth 0 info)) (body (if (org-babel-noweb-p (nth 2 info) :eval)