Re: [O] org babel before excute hook
I have confirmed that this works. Thank you. On 10/14/13, Eric Schulte wrote: > I just pushed up a change so that `org-confirm-babel-evaluate' will > always be called from the head of the code block being evaluated. So > the info can always be reached with something like the following. > > (setf org-confirm-babel-evaluate > (lambda (&rest args) > (message "info: %S" (org-babel-get-src-block-info 'light)) > nil)) -- The Kafka Pandemic: http://thekafkapandemic.blogspot.com The disease DOES progress. MANY people have died from it. ANYBODY can get it. Denmark: free Karina Hansen NOW.
Re: [O] org babel before excute hook
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_fhgn/T/temp302IjV]] >> [[file:/var/folders/kb/2hchpbyj7lb6z76l0q73w_fhgn/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
Re: [O] org babel before excute hook
Samuel Wales writes: > In case it helps, there is org-confirm-babel-evaluate. > > (But I have not found it to be useful, because it does not seem to > place point in a place where you can check properties, etc.) > I just pushed up a change so that `org-confirm-babel-evaluate' will always be called from the head of the code block being evaluated. So the info can always be reached with something like the following. (setf org-confirm-babel-evaluate (lambda (&rest args) (message "info: %S" (org-babel-get-src-block-info 'light)) nil)) > > Samuel -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D
Re: [O] org babel before excute hook
if anyone is interested in this, a simple defadvice appears to be a good option, I put (defadvice org-babel-execute-maybe (around org-babel-stop-on-collision) "stop execution of result file defined more than once" (let ((info (org-babel-get-src-block-info))) (setq result-file (cdr (assoc :file (nth 2 info (if (save-excursion (goto-char 0) (re-search-forward (concat ":file +" result-file) nil t) (re-search-forward (concat ":file +" result-file) nil t)) (error (concat result-file " defined in more than one source block")) ad-do-it))) (ad-activate 'org-babel-execute-maybe) in my .emacs and appear to get the desired functionality 2013/10/13 Samuel Wales > In case it helps, there is org-confirm-babel-evaluate. > > (But I have not found it to be useful, because it does not seem to > place point in a place where you can check properties, etc.) > > Samuel > > -- > The Kafka Pandemic: http://thekafkapandemic.blogspot.com > > The disease DOES progress. MANY people have died from it. ANYBODY can > get it. > > Denmark: free Karina Hansen NOW. >
Re: [O] org babel before excute hook
In case it helps, there is org-confirm-babel-evaluate. (But I have not found it to be useful, because it does not seem to place point in a place where you can check properties, etc.) Samuel -- The Kafka Pandemic: http://thekafkapandemic.blogspot.com The disease DOES progress. MANY people have died from it. ANYBODY can get it. Denmark: free Karina Hansen NOW.
Re: [O] org babel before excute hook
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 (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_fhgn/T/temp302IjV]] > [[file:/var/folders/kb/2hchpbyj7lb6z76l0q73w_fhgn/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] > > > > >
Re: [O] org babel before excute hook
I thought about temp files, but that makes the file names cryptic which is inconvenient for communication without people outside org.. also, I tend recompile figures many times which would cause a lot of cluttering files that are hard to delete since you don't know which file is the one currently linked in your org file... Anyway, I made this instead which appears to work as I intended (defun org-babel-about-to-overwrite-file () (let ((info (org-babel-get-src-block-info))) (setq result-file (cdr (assoc :file (nth 2 info (if (save-excursion (goto-char 0) (re-search-forward (concat ":file +" result-file) nil t) (re-search-forward (concat ":file +" result-file) nil t)) (message (concat result-file " defined in more than one source block")) (org-babel-execute-maybe (add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-about-to-overwrite-file) 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_fhgn/T/temp302IjV]] > [[file:/var/folders/kb/2hchpbyj7lb6z76l0q73w_fhgn/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] > > > > >
Re: [O] org babel before excute hook
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_fhgn/T/temp302IjV]] [[file:/var/folders/kb/2hchpbyj7lb6z76l0q73w_fhgn/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]
Re: [O] org babel before excute hook
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. John John --- John Kitchin Associate Professor Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 http://kitchingroup.cheme.cmu.edu On Fri, Oct 11, 2013 at 9:56 AM, Henning Redestig wrote: > I collaborate with different people on the same orgfile which contains > many source blocks that generate graphics by e.g. :results graphics abc.pdf > > It can happen that I or someone else accidentally create another > independent source block that overwrites my abc.pdf which is of course very > bad. > > I would like to add functionality so that org-babel-execute-src-block > checks if in :results graphics FILE, FILE is already referred to by another > source block and if so refuse to evaluate. > > However, I only see a org-babel-after-execute-hook but no > org-babel-before-execute-hook > > any reason for this? I could try to write a patch but thought I'd ask > first. > > or if there is an even better approach to avoid overwriting output > from different source blocks.. > > //Henning >
[O] org babel before excute hook
I collaborate with different people on the same orgfile which contains many source blocks that generate graphics by e.g. :results graphics abc.pdf It can happen that I or someone else accidentally create another independent source block that overwrites my abc.pdf which is of course very bad. I would like to add functionality so that org-babel-execute-src-block checks if in :results graphics FILE, FILE is already referred to by another source block and if so refuse to evaluate. However, I only see a org-babel-after-execute-hook but no org-babel-before-execute-hook any reason for this? I could try to write a patch but thought I'd ask first. or if there is an even better approach to avoid overwriting output from different source blocks.. //Henning