From: Aaron Ecay <aaronecay@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH 09/10] Remove org-babel-check-confirm-evaluate macro
Date: Mon, 1 Apr 2013 01:42:23 -0400 [thread overview]
Message-ID: <1364794944-13826-10-git-send-email-aaronecay@gmail.com> (raw)
In-Reply-To: <1364794944-13826-1-git-send-email-aaronecay@gmail.com>
* 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
next prev parent reply other threads:[~2013-04-01 5:42 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-01 5:42 [PATCH 00/10] babel cleanups Aaron Ecay
2013-04-01 5:42 ` [PATCH 01/10] Fix org-babel-R-initiate-session Aaron Ecay
2013-04-03 13:46 ` Eric Schulte
2013-04-01 5:42 ` [PATCH 02/10] Clean up org-babel-expand-body: functions for awk and picolisp Aaron Ecay
2013-04-03 13:56 ` Eric Schulte
2013-04-01 5:42 ` [PATCH 03/10] Clean up various org-babel-*-maybe commands Aaron Ecay
2013-04-02 19:31 ` Achim Gratz
2013-04-03 14:18 ` Bastien
2013-04-18 7:03 ` Aaron Ecay
2013-04-18 8:06 ` [PATCH 1/4] " Aaron Ecay
2013-04-18 10:28 ` Bastien
2013-04-20 10:10 ` [PATCH 03/10] " Eric Schulte
2013-04-22 3:52 ` Aaron Ecay
2013-04-01 5:42 ` [PATCH 04/10] Add 'light argument to some uses of org-babel-get-src-block-info Aaron Ecay
2013-04-03 14:09 ` Eric Schulte
2013-04-18 7:09 ` Aaron Ecay
2013-04-20 10:09 ` Eric Schulte
2013-04-22 3:51 ` Aaron Ecay
2013-04-01 5:42 ` [PATCH 05/10] Remove info arg from several org-babel functions Aaron Ecay
2013-04-03 13:58 ` Eric Schulte
2013-04-18 7:07 ` Aaron Ecay
2013-04-01 5:42 ` [PATCH 06/10] Use prefix arg in org-edit-special Aaron Ecay
2013-04-03 13:42 ` Eric Schulte
2013-04-03 17:02 ` Bastien
2013-04-01 5:42 ` [PATCH 07/10] Simplify org-babel-execute-src-block Aaron Ecay
2013-04-02 19:41 ` Achim Gratz
2013-04-03 13:54 ` Eric Schulte
2013-04-03 17:05 ` Achim Gratz
2013-04-03 17:20 ` Eric Schulte
2013-04-01 5:42 ` [PATCH 08/10] Fix testing/lisp/test-ob-emacs-lisp.el Aaron Ecay
2013-04-03 13:47 ` Eric Schulte
2013-04-01 5:42 ` Aaron Ecay [this message]
2013-04-02 19:53 ` [PATCH 09/10] Remove org-babel-check-confirm-evaluate macro Achim Gratz
2013-04-03 14:05 ` Eric Schulte
2013-04-01 5:42 ` [PATCH 10/10] Document how :var introduces code block dependencies Aaron Ecay
2013-04-03 14:04 ` Eric Schulte
2013-04-02 22:14 ` [PATCH 00/10] babel cleanups Eric Schulte
2013-04-03 14:13 ` Eric Schulte
2013-04-03 16:21 ` Bastien
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1364794944-13826-10-git-send-email-aaronecay@gmail.com \
--to=aaronecay@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.