emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] Programatic validation of code blocks for subsequent execution witho


From: Jonathan Leech-Pepin
Subject: [O] Programatic validation of code blocks for subsequent execution without prompting
Date: Wed, 15 Oct 2014 11:00:40 -0400

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_<src> 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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]