3

When I execute a source block, I'd like to get a timestamp on the +RESULTS block so that I can remember when it was last executed. Is there a built-in option for this or do I need to go in and add a hook or a advise a function somewhere?

1

I came here wanting the same thing, but finding no answers, I wrote my own defadvice wrapper:

NOT BATTLE TESTED:

#+BEGIN_SRC emacs-lisp
(defadvice org-babel-execute-src-block (after org-babel-record-execute-timestamp)
  (let ((code-block-params (nth 2 (org-babel-get-src-block-info)))
        (code-block-name (nth 4 (org-babel-get-src-block-info))))
    (let ((timestamp (cdr (assoc :timestamp code-block-params)))
          (result-params (assoc :result-params code-block-params)))
      (if (and (equal timestamp "t") (> (length code-block-name) 0))
          (save-excursion
            (search-forward-regexp (concat "#\\+RESULTS\\(\\[.*\\]\\)?: " 
                                           code-block-name))
            (beginning-of-line)
            (search-forward "RESULTS")
            (kill-line)
            (insert (concat (format-time-string "[%F %r]: ") code-block-name)))
        (if (equal timestamp "t")
            (message (concat "Result timestamping requires a #+NAME: "
                             "and a ':results output' argument.")))))))
(ad-activate 'org-babel-execute-src-block)
#+END_SRC

#+NAME: test-no-timestamp
#+BEGIN_SRC shell :results output
echo "This ones doesn't have the right args for timestamping"
#+END_SRC

#+RESULTS: test-no-timestamp
: This ones doesn't have the right args for timestamping

#+NAME: test-timestamp
#+BEGIN_SRC shell :results output :timestamp t
echo "This one should have a timestamp. Run me again, I update."
#+END_SRC

#+RESULTS[2017-10-03 05:19:09 AM]: test-timestamp
: This one should have a timestamp. Run me again, I update.
  • This is nice. Have you found a better way to implement this, in the last two years? – Quarky Quanta Sep 1 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.