Browse Source

babel: :eval header argument takes arguments "never" and "query" to limit evaluation

* lisp/ob.el (org-babel-confirm-evaluate): adding a new :eval header
  argument which can be used to control evaluation

* doc/org.texi (eval): adding documentation for the new :eval header
  argument
Eric Schulte 15 years ago
parent
commit
e4cfd468a0
2 changed files with 34 additions and 13 deletions
  1. 20 5
      doc/org.texi
  2. 14 8
      lisp/ob.el

+ 20 - 5
doc/org.texi

@@ -11411,13 +11411,17 @@ The following header arguments are defined:
 
 
 @menu
 @menu
 * var::				Pass arguments to code blocks
 * var::				Pass arguments to code blocks
-* results::			Specify the type of results and how they will be collectd and handled
+* results::			Specify the type of results and how they will
+                                be collectd and handled
 * file::			Specify a path for file output
 * file::			Specify a path for file output
-* dir and remote execution::	Specify the default directory for code block execution
+* dir and remote execution::	Specify the default directory for code block
+                                execution
 * exports::			Export code and/or results
 * exports::			Export code and/or results
 * tangle::			Toggle tangling and specify file name
 * tangle::			Toggle tangling and specify file name
-* no-expand::			Turn off variable assignment and noweb expansion during tangling
-* comments::                    Toggle insertion of comments in tangled code files
+* no-expand::			Turn off variable assignment and noweb
+                                expansion during tangling
+* comments::                    Toggle insertion of comments in tangled
+                                code files
 * session::			Preserve the state of code evaluation
 * session::			Preserve the state of code evaluation
 * noweb::			Toggle expansion of noweb references
 * noweb::			Toggle expansion of noweb references
 * cache::			Avoid re-evaluating unchanged code blocks
 * cache::			Avoid re-evaluating unchanged code blocks
@@ -11425,6 +11429,7 @@ The following header arguments are defined:
 * colnames::			Handle column names in tables
 * colnames::			Handle column names in tables
 * rownames::			Handle row names in tables
 * rownames::			Handle row names in tables
 * shebang::			Make tangled files executable
 * shebang::			Make tangled files executable
+* eval::                        Limit evaluation of specific code blocks
 @end menu
 @end menu
 
 
 @node var, results, Specific header arguments, Specific header arguments
 @node var, results, Specific header arguments, Specific header arguments
@@ -12003,7 +12008,7 @@ and is then reapplied to the results.
 @end example
 @end example
 @end itemize
 @end itemize
 
 
-@node shebang,  , rownames, Specific header arguments
+@node shebang, eval, rownames, Specific header arguments
 @subsubsection @code{:shebang}
 @subsubsection @code{:shebang}
 
 
 Setting the @code{:shebang} header argument to a string value
 Setting the @code{:shebang} header argument to a string value
@@ -12011,6 +12016,16 @@ Setting the @code{:shebang} header argument to a string value
 first line of any tangled file holding the code block, and the file
 first line of any tangled file holding the code block, and the file
 permissions of the tangled file are set to make it executable.
 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 two arguments ``never'' and
+``query''.  @code{:eval never} 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.
+
 @node Results of evaluation, Noweb reference syntax, Header arguments, Working With Source Code
 @node Results of evaluation, Noweb reference syntax, Header arguments, Working With Source Code
 @section Results of evaluation
 @section Results of evaluation
 @cindex code block, results of evaluation
 @cindex code block, results of evaluation

+ 14 - 8
lisp/ob.el

@@ -171,14 +171,20 @@ any confirmation from the user.
 
 
 Note disabling confirmation may result in accidental evaluation
 Note disabling confirmation may result in accidental evaluation
 of potentially harmful code."
 of potentially harmful code."
-  (unless (or (not (if (functionp org-confirm-babel-evaluate)
-		       (funcall org-confirm-babel-evaluate
-				(nth 0 info) (nth 1 info))
-		     org-confirm-babel-evaluate))
-	      (yes-or-no-p
-	       (format "Evaluate this%scode on your system?"
-		       (if info (format " %s " (nth 0 info)) " "))))
-    (error "evaluation aborted")))
+  (let ((eval (cdr (assoc :eval (nth 2 info)))))
+    (when (or (equal eval "never")
+	      (and (equal eval "query")
+		   (not (yes-or-no-p
+			(format "Evaluate this%scode on your system?"
+				(if info (format " %s " (nth 0 info)) " ")))))
+	      (and (or (and (functionp org-confirm-babel-evaluate)
+			    (funcall org-confirm-babel-evaluate
+				     (nth 0 info) (nth 1 info)))
+		       org-confirm-babel-evaluate)
+		   (not (yes-or-no-p
+			 (format "Evaluate this%scode on your system?"
+				 (if info (format " %s " (nth 0 info)) " "))))))
+      (error "evaluation aborted"))))
 
 
 ;;;###autoload
 ;;;###autoload
 (defun org-babel-execute-src-block-maybe ()
 (defun org-babel-execute-src-block-maybe ()