emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Jonathan Leech-Pepin <jonathan.leechpepin@gmail.com>
To: Org Mode Mailing List <emacs-orgmode@gnu.org>
Subject: Programatic validation of code blocks for subsequent execution without prompting
Date: Wed, 15 Oct 2014 11:00:40 -0400	[thread overview]
Message-ID: <CAEWDx5edNgmn5OXwnmoL2Y0FW=chEqHPFSzgOmjsf1TCZgNDJQ@mail.gmail.com> (raw)

[-- 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 --]

                 reply	other threads:[~2014-10-15 15:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEWDx5edNgmn5OXwnmoL2Y0FW=chEqHPFSzgOmjsf1TCZgNDJQ@mail.gmail.com' \
    --to=jonathan.leechpepin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).