emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Henning Redestig <henning.red@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: org babel before excute hook
Date: Mon, 14 Oct 2013 07:29:22 -0600	[thread overview]
Message-ID: <87ob6s6kog.fsf@gmail.com> (raw)
In-Reply-To: CAO8D54zt=yTZozBf3cPrg3Pu2zpX8xuW9Pw6MEq6--Y=nuSErA@mail.gmail.com

Henning Redestig <henning.red@gmail.com> writes:

> Is it possible to add a function to org-ctrl-c-ctrl-c-hook without patching
> ob-core.el? If I just add something like
>

Yes, see the documentation of `org-confirm-babel-evaluate'.  So the
function posted in your previous email could be changed to something
like...

    (setf org-confirm-babel-evaluate
          (lambda (&rest args)
            (let* ((info (org-babel-get-src-block-info))
                   (result-file (cdr (assoc :file (nth 2 info))))
                   (duplicat-file-p
                    (save-excursion
                      (goto-char 0)
                      (re-search-forward (concat ":file +" result-file) nil t)
                      (re-search-forward (concat ":file +" result-file) nil t)))))
            (if duplicate-file-p
                (prog1 t (message "duplicate result file"))
                nil)))

>
> (add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-stop-if-file-collision)
>
> in my .emacs I notice that my addition gets overwritten later via the
> autoloads (I think) that are defined in ob-core.el..
>
>
>
> 2013/10/12 Charles Berry <ccberry@ucsd.edu>
>
>> John Kitchin <jkitchin <at> andrew.cmu.edu> writes:
>>
>> >
>> >
>> >
>> > I have a related kind of problem. When preparing notes
>> > for a class, I may end up with 70 code blocks in an org file, many of
>> > which create graphics. I am always worried about accidentally using the
>> > same filename and overwriting a graphic from an earlier block. A unique,
>> >  but reproducible filename would be sufficient for my needs.
>> >
>>
>> Header arg values can be elisp calls. You can use `make-temp-file'.
>>
>> So every time this block is executed, a new file is created and the
>> file link is added to the results.
>>
>> #+BEGIN_SRC R :results output append :file (make-temp-file "temp")
>> cat(date(),"\n")
>> #+END_SRC
>>
>> #+RESULTS:
>> [[file:/var/folders/kb/2hchpbyj7lb6z76l0q73w_fh0000gn/T/temp302IjV]]
>> [[file:/var/folders/kb/2hchpbyj7lb6z76l0q73w_fh0000gn/T/temp3028Lu]]
>>
>> See `temporary-file-directory', too, if you want to use this, as the
>> default may not be what you intend.
>>
>>
>> You might want to use this:
>>
>> #+BEGIN_SRC emacs-lisp
>>   (defun local-tfile (file)
>>     (let ((temporary-file-directory "."))
>>       (make-temp-file file)))
>> #+END_SRC
>>
>> Then the files go in the local directory when this is executed:
>>
>> #+BEGIN_SRC R :file (local-tfile "tfile") :results output append
>> cat(date(),"\n")
>> #+END_SRC
>>
>> You might not want `append' in this case.
>>
>>
>> HTH,
>>
>> Chuck
>>
>> [rest deleted]
>>
>>
>>
>>
>>

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

      parent reply	other threads:[~2013-10-14 13:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-11 13:56 org babel before excute hook Henning Redestig
2013-10-11 20:31 ` John Kitchin
2013-10-12  2:28   ` Charles Berry
2013-10-12 13:11     ` Henning Redestig
2013-10-13 21:22     ` Henning Redestig
2013-10-13 21:35       ` Samuel Wales
2013-10-14  6:45         ` Henning Redestig
2013-10-14  8:11           ` [babel] Feature request - WAS: " Rainer M Krug
2013-10-14 13:24         ` Eric Schulte
2013-10-26 22:05           ` Samuel Wales
2013-10-14 13:29       ` Eric Schulte [this message]

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=87ob6s6kog.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=henning.red@gmail.com \
    /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).