the :eval header argument now takes 4(6) possible values

* doc/org.texi (eval): Documenting the full range of :eval header
  argument values.
* lisp/ob.el (org-babel-confirm-evaluate): Adding support for new
  range of :eval header arguments.
* testing/lisp/test-ob.el (test-ob/eval-header-argument): Testing the
  :eval header argument.
This commit is contained in:
Eric Schulte 2011-11-22 07:32:39 -07:00
parent c166760fcc
commit a998cae722
3 changed files with 44 additions and 10 deletions

View File

@ -13112,14 +13112,23 @@ permissions of the tangled file are set to make it executable.
@node eval, , shebang, Specific header arguments
@subsubsection @code{:eval}
The @code{:eval} header argument can be used to limit the evaluation of
specific code blocks. @code{:eval} accepts three arguments ``never'',
``query'' and ``non-export''. @code{:eval never} (or @code{:eval no}) will
ensure that a code block is never evaluated, this can be useful for
protecting against the evaluation of dangerous code blocks. @code{:eval
query} will require a query for every execution of a code block regardless of
the value of the @code{org-confirm-babel-evaluate} variable and @code{:eval
non-export} will inhibit the evaluation of code blocks during export but will
still allow interactive evaluation.
specific code blocks. The @code{:eval} header argument can be useful for
protecting against the evaluation of dangerous code blocks or to ensure that
evaluation will require a query regardless of the value of the
@code{org-confirm-babel-evaluate} variable. The possible values of
@code{:eval} and their effects are shown below.
@table @code
@item never or no
The code block will not be evaluated under any circumstances.
@item query
Evaluation of the code block will require a query.
@item never-export or no-export
The code block will not be evaluated during export but may still be called
interactively.
@item query-export
Evaluation of the code block during export will require a query.
@end table
If this header argument is not set then evaluation is determined by the value
of the @code{org-confirm-babel-evaluate} variable see @ref{Code evaluation

View File

@ -252,12 +252,15 @@ of potentially harmful code."
(let* ((eval (or (cdr (assoc :eval (nth 2 info)))
(when (assoc :noeval (nth 2 info)) "no")))
(query (cond ((equal eval "query") t)
((and org-current-export-file
(equal eval "query-export")) t)
((functionp org-confirm-babel-evaluate)
(funcall org-confirm-babel-evaluate
(nth 0 info) (nth 1 info)))
(t org-confirm-babel-evaluate))))
(if (or (equal eval "never") (equal eval "no")
(and (equal eval "non-export") org-current-export-file)
(and org-current-export-file (or (equal eval "no-export")
(equal eval "never-export")))
(and query
(not (yes-or-no-p
(format "Evaluate this%scode block%son your system? "
@ -266,7 +269,8 @@ of potentially harmful code."
(format " (%s) " (nth 4 info)) " "))))))
(prog1 nil (message "Evaluation %s"
(if (or (equal eval "never") (equal eval "no")
(equal eval "non-export"))
(equal eval "no-export")
(equal eval "never-export"))
"Disabled" "Aborted")))
t)))

View File

@ -531,6 +531,27 @@ on two lines
(forward-line 6)
(should (looking-at ": 2")))))
(ert-deftest test-ob/eval-header-argument ()
(flet ((check-eval (eval runp)
(org-test-with-temp-text (format "#+begin_src emacs-lisp :eval %s
(setq foo :evald)
#+end_src" eval)
(let ((foo :not-run))
(if runp
(progn (should (org-babel-execute-src-block))
(should (eq foo :evald)))
(progn (should-not (org-babel-execute-src-block))
(should-not (eq foo :evald))))))))
(check-eval "never" nil)
(check-eval "no" nil)
(check-eval "never-export" t)
(check-eval "no-export" t)
(let ((org-current-export-file "something"))
(check-eval "never" nil)
(check-eval "no" nil)
(check-eval "never-export" nil)
(check-eval "no-export" nil))))
(provide 'test-ob)
;;; test-ob ends here