From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: org babel before excute hook Date: Mon, 14 Oct 2013 07:29:22 -0600 Message-ID: <87ob6s6kog.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:51762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VViHs-0004UL-9U for emacs-orgmode@gnu.org; Mon, 14 Oct 2013 09:34:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VViHh-0001hz-A7 for emacs-orgmode@gnu.org; Mon, 14 Oct 2013 09:34:20 -0400 Received: from mail-pb0-x22a.google.com ([2607:f8b0:400e:c01::22a]:59650) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VViHh-0001hv-2r for emacs-orgmode@gnu.org; Mon, 14 Oct 2013 09:34:09 -0400 Received: by mail-pb0-f42.google.com with SMTP id un15so7348661pbc.1 for ; Mon, 14 Oct 2013 06:34:08 -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: Henning Redestig Cc: emacs-orgmode@gnu.org Henning Redestig 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 > >> John Kitchin 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