From mboxrd@z Thu Jan 1 00:00:00 1970 From: Aaron Ecay Subject: [PATCH 09/10] Remove org-babel-check-confirm-evaluate macro Date: Mon, 1 Apr 2013 01:42:23 -0400 Message-ID: <1364794944-13826-10-git-send-email-aaronecay@gmail.com> References: <1364794944-13826-1-git-send-email-aaronecay@gmail.com> Return-path: Received: from eggs.gnu.org ([208.118.235.92]:37760) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMXVw-0002pv-Gm for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 01:42:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMXVt-0000x3-Qr for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 01:42:40 -0400 Received: from mail-qe0-f51.google.com ([209.85.128.51]:64310) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMXVt-0000wt-L5 for emacs-orgmode@gnu.org; Mon, 01 Apr 2013 01:42:37 -0400 Received: by mail-qe0-f51.google.com with SMTP id nd7so1066349qeb.10 for ; Sun, 31 Mar 2013 22:42:37 -0700 (PDT) In-Reply-To: <1364794944-13826-1-git-send-email-aaronecay@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org * 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