Question

Is there a way to save a history of executions of Babel code blocks? Basically I want to record the block, timestamp, and filename.

Maybe if it's not there, someone knows a similar function that I can hack? Basically I need a way to get a hold of current selection, timestamp and filename, and a way of appending it to a text file.

Was it helpful?

Solution

Here what you can do:

  • advice a function org-babel-execute-src-block
  • put results into a buffer, "babel-log" in my example

You can also write results into a log file.

(require 'time-stamp)

(defadvice org-babel-execute-src-block (after log-org-babel-execute-src-block activate)
  (org-narrow-to-block)
  (let ((file (buffer-file-name)) (src-block (buffer-substring-no-properties (point-min) (point-max))))
    (with-current-buffer "babel-log"
      (insert (concat "file:" file " time:" (time-stamp-string) " block\n" src-block "\n\n")))
    )
  (widen)
  )
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top