From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jonathan Leech-Pepin Subject: Programatic validation of code blocks for subsequent execution without prompting Date: Wed, 15 Oct 2014 11:00:40 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c1630069bf380505776656 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41575) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeQ4X-0001Aw-89 for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 11:01:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeQ4U-0001oz-I0 for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 11:01:05 -0400 Received: from mail-qa0-x236.google.com ([2607:f8b0:400d:c00::236]:52772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeQ4U-0001om-DY for emacs-orgmode@gnu.org; Wed, 15 Oct 2014 11:01:02 -0400 Received: by mail-qa0-f54.google.com with SMTP id i13so928240qae.41 for ; Wed, 15 Oct 2014 08:01:01 -0700 (PDT) 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: Org Mode Mailing List --001a11c1630069bf380505776656 Content-Type: text/plain; charset=UTF-8 Hello all, I just wanted to share a bit of code I worked up for an emacs.stackexchange.com question regarding evaluation code blocks without confirmation if the code has not changed (useful when exporting multiple times or using in call_ where you will not have a #+RESULT block to cache results with. The question and answer can be found here: http://emacs.stackexchange.com/questions/499/finding-and-executing-org-babel-snippets-programatically/510#510 The code in question: (defvar my/babel-hashes 'nil) (defun my/babel-hashed-confirm (lang body) (let ((check (list lang (md5 body)))) ;; If not hashed, prompt (if (not (member (list lang (md5 body)) my/babel-hashes)) ;; Ask if you want to hash (if (yes-or-no-p "Store hash for block? ") ;; Hash is added, proceed with evaluation (progn (add-to-list 'my/babel-hashes check) 'nil) ;; Return 't to prompt for evaluation 't)))) (setq org-confirm-babel-evaluate 'my/babel-hashed-confirm) This allows for re-evaluation of the same code block (regardless of call location or variables used) without subsequent prompting as long as the body of the code block has not changed. This will prevent accidental insertions, or unintended changes from being evaluated without prompting, while allowing re-evaluation as needed (For example an sql query that will have different results over time). Regards, Jon --001a11c1630069bf380505776656 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hello all,

I ju= st wanted to share a bit of code I worked up for an emacs.stackexchange.com question regarding evaluati= on code blocks without confirmation if the code has not changed (useful whe= n exporting multiple times or using in call_<src> where you will not = have a #+RESULT block to cache results with.

The question and = answer can be found here: ht= tp://emacs.stackexchange.com/questions/499/finding-and-executing-org-babel-= snippets-programatically/510#510

The code in question:
=
(defvar my/babel-hashes 'nil)
(defun my/babel-hashed-confirm (lang body)
  (let ((check (list lang (md5 body))))
    ;; If not hashed, prompt
    (if (not (member (list lang (md5 body)) my/babel-hashes))
        ;; Ask if you want to hash
        (if (yes-or-no-p "Store hash for block? ")
            ;; Hash is added, proceed with evaluation
            (progn
              (add-to-list 'my/babel-hashes check)
              'nil)
          ;; Return 't to prompt for evaluation
          't))))

(setq org-confirm-babel-evaluate 'my/babel-hashed-confirm)
=

This allows for re-evaluation of the same code block (r= egardless of call location or variables used) without subsequent prompting = as long as the body of the code block has not changed.=C2=A0 This will prev= ent accidental insertions, or unintended changes from being evaluated witho= ut prompting, while allowing re-evaluation as needed (For example an sql qu= ery that will have different results over time).

Regards,
J= on
--001a11c1630069bf380505776656--