emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Programatic validation of code blocks for subsequent execution without prompting
@ 2014-10-15 15:00 Jonathan Leech-Pepin
  0 siblings, 0 replies; only message in thread
From: Jonathan Leech-Pepin @ 2014-10-15 15:00 UTC (permalink / raw)
  To: Org Mode Mailing List

[-- Attachment #1: Type: text/plain, Size: 1461 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1838 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-10-15 15:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-15 15:00 Programatic validation of code blocks for subsequent execution without prompting Jonathan Leech-Pepin

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).