* [PATCH] org-babel-confirm-evaluate when org-confirm-babel-evaluate is a function
@ 2010-12-20 19:33 Vladimir Alexiev
2010-12-21 16:38 ` Eric Schulte
0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Alexiev @ 2010-12-20 19:33 UTC (permalink / raw)
To: emacs-orgmode
I tried following http://orgmode.org/worg/org-contribute.php to the letter.
But this is my first patch (and first time using git & magit), so please kindly
give me feedback if something is not right.
* doc/org.texi: org-confirm-babel-evaluate: add example for using a
function
* lisp/ob.el (org-babel-confirm-evaluate): Fix for the case when
org-confirm-babel-evaluate is a function (used to always ask no matter
what the function returns)
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -12662,9 +12662,19 @@ Make sure you know what you are doing before
customizing the variables
which take off the default security brakes.
@defopt org-confirm-babel-evaluate
-When set to t user is queried before code block evaluation
+When t (the default), the user is asked before every code block evaluation.
+When nil, the user is not asked.
+When set to a function, it is called with two arguments (language and body of
the code
+block) and should return t to ask and nil not to ask.
@end defopt
+For example, here is how to execute "ditaa" code (which is considered safe)
without asking:
+@example
+(defun my-org-confirm-babel-evaluate (lang body)
+ (not (string= lang "ditaa"))) ; don't ask for ditaa
+(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
+@end example
+
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -209,11 +209,11 @@ Note disabling confirmation may result in accidental
evaluation
of potentially harmful code."
(let* ((eval (or (cdr (assoc :eval (nth 2 info)))
(when (assoc :noeval (nth 2 info)) "no")))
- (query (or (equal eval "query")
- (if (functionp org-confirm-babel-evaluate)
- (funcall org-confirm-babel-evaluate
- (nth 0 info) (nth 1 info))
- org-confirm-babel-evaluate))))
+ (query (cond ((equal eval "query"))
+ ((functionp org-confirm-babel-evaluate)
+ (funcall org-confirm-babel-evaluate
+ (nth 0 info) (nth 1 info)))
+ ((org-confirm-babel-evaluate)))))
(if (or (equal eval "never") (equal eval "no")
(and query
(not (yes-or-no-p
TINYCHANGE
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] org-babel-confirm-evaluate when org-confirm-babel-evaluate is a function
2010-12-20 19:33 [PATCH] org-babel-confirm-evaluate when org-confirm-babel-evaluate is a function Vladimir Alexiev
@ 2010-12-21 16:38 ` Eric Schulte
0 siblings, 0 replies; 2+ messages in thread
From: Eric Schulte @ 2010-12-21 16:38 UTC (permalink / raw)
To: Vladimir Alexiev; +Cc: emacs-orgmode
Hi Vladimir,
Thanks very much for this patch, it is great to receive patches that
update the documentation as well as the code. I've just applied a
slightly modified version of your patch.
Thanks -- Eric
Vladimir Alexiev <vladimir@sirma.bg> writes:
> I tried following http://orgmode.org/worg/org-contribute.php to the letter.
> But this is my first patch (and first time using git & magit), so please kindly
> give me feedback if something is not right.
>
> * doc/org.texi: org-confirm-babel-evaluate: add example for using a
> function
> * lisp/ob.el (org-babel-confirm-evaluate): Fix for the case when
> org-confirm-babel-evaluate is a function (used to always ask no matter
> what the function returns)
>
> --- a/doc/org.texi
> +++ b/doc/org.texi
> @@ -12662,9 +12662,19 @@ Make sure you know what you are doing before
> customizing the variables
> which take off the default security brakes.
>
> @defopt org-confirm-babel-evaluate
> -When set to t user is queried before code block evaluation
> +When t (the default), the user is asked before every code block evaluation.
> +When nil, the user is not asked.
> +When set to a function, it is called with two arguments (language and body of
> the code
> +block) and should return t to ask and nil not to ask.
> @end defopt
>
> +For example, here is how to execute "ditaa" code (which is considered safe)
> without asking:
> +@example
> +(defun my-org-confirm-babel-evaluate (lang body)
> + (not (string= lang "ditaa"))) ; don't ask for ditaa
> +(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
> +@end example
> +
>
> --- a/lisp/ob.el
> +++ b/lisp/ob.el
> @@ -209,11 +209,11 @@ Note disabling confirmation may result in accidental
> evaluation
> of potentially harmful code."
> (let* ((eval (or (cdr (assoc :eval (nth 2 info)))
> (when (assoc :noeval (nth 2 info)) "no")))
> - (query (or (equal eval "query")
> - (if (functionp org-confirm-babel-evaluate)
> - (funcall org-confirm-babel-evaluate
> - (nth 0 info) (nth 1 info))
> - org-confirm-babel-evaluate))))
> + (query (cond ((equal eval "query"))
> + ((functionp org-confirm-babel-evaluate)
> + (funcall org-confirm-babel-evaluate
> + (nth 0 info) (nth 1 info)))
> + ((org-confirm-babel-evaluate)))))
> (if (or (equal eval "never") (equal eval "no")
> (and query
> (not (yes-or-no-p
>
> TINYCHANGE
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-12-21 16:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-20 19:33 [PATCH] org-babel-confirm-evaluate when org-confirm-babel-evaluate is a function Vladimir Alexiev
2010-12-21 16:38 ` Eric Schulte
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).