emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH 09/10] Remove org-babel-check-confirm-evaluate macro


From: Aaron Ecay
Subject: [O] [PATCH 09/10] Remove org-babel-check-confirm-evaluate macro
Date: Mon, 1 Apr 2013 01:42:23 -0400

* lisp/ob-core.el (org-babel-check-confirm-evaluate): remove
  (org-babel-check-evaluate),
  (org-babel-confirm-evaluate): move logic here

This macro is used in only two places, and has two almost-independent
complex logics coded into it.  So, suppress the macro and move the logic
into the respective functions.
---
 lisp/ob-core.el | 89 ++++++++++++++++++++++++++-------------------------------
 1 file changed, 40 insertions(+), 49 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index d8c11ee..65c5a0b 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -284,49 +284,26 @@ Returns a list
       (setf (nth 2 info) (org-babel-process-params (nth 2 info))))
     (when info (append info (list name indent)))))
 
-(defvar org-current-export-file) ; dynamically bound
-(defmacro org-babel-check-confirm-evaluate (info &rest body)
-  "Evaluate BODY with special execution confirmation variables set.
-
-Specifically; NOEVAL will indicate if evaluation is allowed,
-QUERY will indicate if a user query is required, CODE-BLOCK will
-hold the language of the code block, and BLOCK-NAME will hold the
-name of the code block."
-  (declare (indent defun))
-  (org-with-gensyms
-      (lang block-body headers name eval eval-no export eval-no-export)
-    `(let* ((,lang           (nth 0 ,info))
-           (,block-body     (nth 1 ,info))
-           (,headers        (nth 2 ,info))
-           (,name           (nth 4 ,info))
-           (,eval           (or (cdr  (assoc :eval   ,headers))
-                                (when (assoc :noeval ,headers) "no")))
-           (,eval-no        (or (equal ,eval "no")
-                                (equal ,eval "never")))
-           (,export         (org-bound-and-true-p org-current-export-file))
-           (,eval-no-export (and ,export (or (equal ,eval "no-export")
-                                             (equal ,eval "never-export"))))
-           (noeval          (or ,eval-no ,eval-no-export))
-           (query           (or (equal ,eval "query")
-                                (and ,export (equal ,eval "query-export"))
-                                (when (functionp org-confirm-babel-evaluate)
-                                  (funcall org-confirm-babel-evaluate
-                                           ,lang ,block-body))
-                                org-confirm-babel-evaluate))
-           (code-block      (if ,info (format  " %s "  ,lang) " "))
-           (block-name      (if ,name (format " (%s) " ,name) " ")))
-       ,@body)))
+;; dynamically bound during export
+(defvar org-current-export-file)
+;; dynamically bound during asynchronous export
+(defvar org-babel-confirm-evaluate-answer-no)
 
 (defsubst org-babel-check-evaluate (info)
   "Check if code block INFO should be evaluated.
 Do not query the user."
-  (org-babel-check-confirm-evaluate info
-    (not (when noeval
-          (message (format "Evaluation of this%scode-block%sis disabled."
-                           code-block block-name))))))
-
- ;; dynamically scoped for asynchroneous export
-(defvar org-babel-confirm-evaluate-answer-no)
+  (let* ((params (nth 2 info))
+        (name (nth 4 info))
+        (eval (cdr (assq :eval params)))
+         (can-eval (not (or (member eval '("never" "no"))
+                           (assq :noeval params)
+                           (and (org-bound-and-true-p org-current-export-file)
+                                (member eval '("no-export" 
"never-export")))))))
+    (when (not can-eval)
+      (message (format "Evaluation of this %s code-block (%s) is disabled."
+                       (nth 0 info)
+                       (if name (concat " (" name ") ") ""))))
+    can-eval))
 
 (defsubst org-babel-confirm-evaluate (info)
   "Confirm evaluation of the code block INFO.
@@ -341,16 +318,30 @@ confirmation from the user.
 
 Note disabling confirmation may result in accidental evaluation
 of potentially harmful code."
-  (org-babel-check-confirm-evaluate info
-    (not (when query
-          (unless
-              (and (not (org-bound-and-true-p
-                         org-babel-confirm-evaluate-answer-no))
-                   (yes-or-no-p
-                    (format "Evaluate this%scode block%son your system? "
-                            code-block block-name)))
-            (message (format "Evaluation of this%scode-block%sis aborted."
-                             code-block block-name)))))))
+
+  (let* ((params (nth 2 info))
+         (name (if (nth 4 info) (concat " (" (nth 4 info) ") ") " "))
+        (eval (cdr (assq :eval params)))
+         (should-query (or (equal eval "query")
+                           (and (org-bound-and-true-p org-current-export-file)
+                                (equal eval "query-export"))
+                           (and (functionp org-confirm-babel-evaluate)
+                                (funcall org-confirm-babel-evaluate
+                                         (nth 0 info)
+                                         (nth 1 info)))
+                          org-confirm-babel-evaluate))
+         (result (or (not should-query)
+                    (not (org-bound-and-true-p
+                          org-babel-confirm-evaluate-answer-no))
+                    (yes-or-no-p
+                     (format "Evaluate this %s code block%son your system? "
+                             (nth 0 info)
+                             name)))))
+    (when (not result)
+      (message (format "Evaluation of this %s code-block%sis aborted."
+                      (nth 0 info)
+                      name)))
+    result))
 
 ;;;###autoload
 (defun org-babel-execute-safely-maybe ()
-- 
1.8.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]