forked from mirrors/org-mode
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:
parent
c166760fcc
commit
a998cae722
25
doc/org.texi
25
doc/org.texi
|
@ -13112,14 +13112,23 @@ permissions of the tangled file are set to make it executable.
|
||||||
@node eval, , shebang, Specific header arguments
|
@node eval, , shebang, Specific header arguments
|
||||||
@subsubsection @code{:eval}
|
@subsubsection @code{:eval}
|
||||||
The @code{:eval} header argument can be used to limit the evaluation of
|
The @code{:eval} header argument can be used to limit the evaluation of
|
||||||
specific code blocks. @code{:eval} accepts three arguments ``never'',
|
specific code blocks. The @code{:eval} header argument can be useful for
|
||||||
``query'' and ``non-export''. @code{:eval never} (or @code{:eval no}) will
|
protecting against the evaluation of dangerous code blocks or to ensure that
|
||||||
ensure that a code block is never evaluated, this can be useful for
|
evaluation will require a query regardless of the value of the
|
||||||
protecting against the evaluation of dangerous code blocks. @code{:eval
|
@code{org-confirm-babel-evaluate} variable. The possible values of
|
||||||
query} will require a query for every execution of a code block regardless of
|
@code{:eval} and their effects are shown below.
|
||||||
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
|
@table @code
|
||||||
still allow interactive evaluation.
|
@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
|
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
|
of the @code{org-confirm-babel-evaluate} variable see @ref{Code evaluation
|
||||||
|
|
|
@ -252,12 +252,15 @@ of potentially harmful code."
|
||||||
(let* ((eval (or (cdr (assoc :eval (nth 2 info)))
|
(let* ((eval (or (cdr (assoc :eval (nth 2 info)))
|
||||||
(when (assoc :noeval (nth 2 info)) "no")))
|
(when (assoc :noeval (nth 2 info)) "no")))
|
||||||
(query (cond ((equal eval "query") t)
|
(query (cond ((equal eval "query") t)
|
||||||
|
((and org-current-export-file
|
||||||
|
(equal eval "query-export")) t)
|
||||||
((functionp org-confirm-babel-evaluate)
|
((functionp org-confirm-babel-evaluate)
|
||||||
(funcall org-confirm-babel-evaluate
|
(funcall org-confirm-babel-evaluate
|
||||||
(nth 0 info) (nth 1 info)))
|
(nth 0 info) (nth 1 info)))
|
||||||
(t org-confirm-babel-evaluate))))
|
(t org-confirm-babel-evaluate))))
|
||||||
(if (or (equal eval "never") (equal eval "no")
|
(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
|
(and query
|
||||||
(not (yes-or-no-p
|
(not (yes-or-no-p
|
||||||
(format "Evaluate this%scode block%son your system? "
|
(format "Evaluate this%scode block%son your system? "
|
||||||
|
@ -266,7 +269,8 @@ of potentially harmful code."
|
||||||
(format " (%s) " (nth 4 info)) " "))))))
|
(format " (%s) " (nth 4 info)) " "))))))
|
||||||
(prog1 nil (message "Evaluation %s"
|
(prog1 nil (message "Evaluation %s"
|
||||||
(if (or (equal eval "never") (equal eval "no")
|
(if (or (equal eval "never") (equal eval "no")
|
||||||
(equal eval "non-export"))
|
(equal eval "no-export")
|
||||||
|
(equal eval "never-export"))
|
||||||
"Disabled" "Aborted")))
|
"Disabled" "Aborted")))
|
||||||
t)))
|
t)))
|
||||||
|
|
||||||
|
|
|
@ -531,6 +531,27 @@ on two lines
|
||||||
(forward-line 6)
|
(forward-line 6)
|
||||||
(should (looking-at ": 2")))))
|
(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)
|
(provide 'test-ob)
|
||||||
|
|
||||||
;;; test-ob ends here
|
;;; test-ob ends here
|
||||||
|
|
Loading…
Reference in a new issue