From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vladimir Alexiev Subject: [PATCH] org-babel-confirm-evaluate when org-confirm-babel-evaluate is a function Date: Mon, 20 Dec 2010 19:33:31 +0000 (UTC) Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=49704 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PUlVi-0006UF-RL for emacs-orgmode@gnu.org; Mon, 20 Dec 2010 14:35:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PUlVh-0004V3-Ru for emacs-orgmode@gnu.org; Mon, 20 Dec 2010 14:35:06 -0500 Received: from lo.gmane.org ([80.91.229.12]:50476) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PUlVh-0004Uq-G9 for emacs-orgmode@gnu.org; Mon, 20 Dec 2010 14:35:05 -0500 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PUlVg-0006xI-Pi for emacs-orgmode@gnu.org; Mon, 20 Dec 2010 20:35:04 +0100 Received: from 85.239.150.142 ([85.239.150.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Dec 2010 20:35:04 +0100 Received: from vladimir by 85.239.150.142 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Dec 2010 20:35:04 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org 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