emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rainer M Krug <Rainer@krugs.de>
To: John Kitchin <jkitchin@andrew.cmu.edu>
Cc: emacs-orgmode@gnu.org
Subject: Re: Set or update timestamp after evaluation of code block?
Date: Tue, 22 Sep 2015 11:45:04 +0200	[thread overview]
Message-ID: <m2eghqhjof.fsf@krugs.de> (raw)
In-Reply-To: <m2mvwehow1.fsf@krugs.de> (Rainer M. Krug's message of "Tue, 22 Sep 2015 09:52:30 +0200")

[-- Attachment #1: Type: text/plain, Size: 5143 bytes --]

Rainer M Krug <Rainer@krugs.de> writes:

> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
>> so picky ;)
>
> Jup - aren't all org users like that?
>
>> Maybe something like this will put that stamp in a comment
>> that won't export.
>>
>> #+BEGIN_SRC emacs-lisp
>> (defun j-add-ts ()
>>   (save-excursion
>>     (re-search-forward "#\\+END_SRC")
>>     (forward-line)
>>     (beginning-of-line)
>>     (when (looking-at "# Last run:")
>>       (kill-line))
>>     (insert (concat
>>              "# Last run: "
>>              (format-time-string "[%Y-%m-%d %a %H:%M:%S]" (current-time))))))
>>
>>
>> (add-hook 'org-babel-after-execute-hook
>>           'j-add-ts)
>>
>> ;(remove-hook 'org-babel-after-execute-hook
>> ;         'j-add-ts)
>> #+END_SRC
>
> Perfect! I added it to my emacs.org just now and I relly like it.

I modified it a bit so that I get the following time stamp before the
source block. Can the fact that I use #+ cause problems? Because I like
the coloring of the LASTRUN line.

Additional question: if I execute the code block from a preceding
e.g. #+NAME: line which belongs to the code block, the line gets
obviously inserted in front of the code block before.

Is there some org wizardry so that I can search the property #+LASTRUN:
which belongs to the code block and replace or insert it?

Or g=can I somehow jump to the beginning of the code block when I am in
a preceding #+ line?

Thanks,

Rainer

--8<---------------cut here---------------start------------->8---
#+LASTRUN: [2015-09-22 Tue 11:37:43]
#+begin_src emacs-lisp 
(defun rmk/org-babel-add-time-stamp-after-execute-before-src-block ()
  (save-excursion
    (re-search-backward "#\\+BEGIN_SRC")
    (forward-line -1)
    (beginning-of-line)
    (when (not (or
                (looking-at "[[:space:]]*$")
                (looking-at "#\\+LASTRUN:")))
      (forward-line 1)
      (newline)
      (forward-line -1))
    (when (looking-at "#\\+LASTRUN:")
      (kill-line))
    (insert (concat
             "#+LASTRUN: "
             (format-time-string "[%Y-%m-%d %a %H:%M:%S]" (current-time))))
))

(add-hook 'org-babel-after-execute-hook
          'rmk/org-babel-add-time-stamp-after-execute-before-src-block)
#+end_src
--8<---------------cut here---------------end--------------->8---

>
> Thanks a lot,
>
> Rainer
>
>>
>>
>> Rainer M Krug writes:
>>
>>> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>>>
>>>> Here is one approach:
>>>>
>>>> #+name: update-timestamp
>>>> #+BEGIN_SRC emacs-lisp :var data=""
>>>> (concat
>>>>  "Last run: "
>>>>  (format-time-string "[%Y-%m-%d %a %H:%M:%S]" (current-time))
>>>>  "\n" data)
>>>> #+END_SRC
>>>>
>>>>
>>>> #+BEGIN_SRC python :post update-timestamp(data=*this*)
>>>> print('hello')
>>>> #+END_SRC
>>>>
>>>> #+RESULTS:
>>>> : Last run: [2015-09-21 Mon 11:09:18]
>>>> : hello
>>>
>>> Thanks John - that looks nice and I like the idea of using
>>> (current-time) and the possibility to format the time string, but this
>>> info will be part of the export - and I only would like tho have the
>>> info in the org file and not in the exported document.
>>>
>>>
>>> Rainer
>>>
>>>>
>>>>
>>>>
>>>> Rainer M Krug writes:
>>>>
>>>>> Eric S Fraga <e.fraga@ucl.ac.uk> writes:
>>>>>
>>>>>> On Monday, 21 Sep 2015 at 14:46, Rainer M Krug wrote:
>>>>>>
>>>>>> [...]
>>>>>>
>>>>>>> Is it possible to set a timestamp (ur update it when it exists already)
>>>>>>> when a code block has been evaluated, so that I have e record when it
>>>>>>> was updated?
>>>>>>
>>>>>> Could you make use of the :post header argument to invoke emacs lisp and
>>>>>> execute org-time-stamp-inactive in some way?
>>>>>
>>>>> Thanks - sounds possible? But if I just use
>>>>>
>>>>> ,----
>>>>> | :post (org-time-stamp-inactive)
>>>>> `----
>>>>>
>>>>> 1) an input is required and
>>>>> 2) the time stamp is inserted before the #+begin_src and makes the block
>>>>> invalid.
>>>>>
>>>>> How can I put the time stamp in the line after the #+end_src or possibly
>>>>> even in the same line, as this does not seem to have an impact on the
>>>>> source block?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Rainer
>>>>
>>>> --
>>>> Professor John Kitchin
>>>> Doherty Hall A207F
>>>> Department of Chemical Engineering
>>>> Carnegie Mellon University
>>>> Pittsburgh, PA 15213
>>>> 412-268-7803
>>>> @johnkitchin
>>>> http://kitchingroup.cheme.cmu.edu
>>
>> --
>> Professor John Kitchin
>> Doherty Hall A207F
>> Department of Chemical Engineering
>> Carnegie Mellon University
>> Pittsburgh, PA 15213
>> 412-268-7803
>> @johnkitchin
>> http://kitchingroup.cheme.cmu.edu

-- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa

Tel :       +33 - (0)9 53 10 27 44
Cell:       +33 - (0)6 85 62 59 98
Fax :       +33 - (0)9 58 10 27 44

Fax (D):    +49 - (0)3 21 21 25 22 44

email:      Rainer@krugs.de

Skype:      RMkrug

PGP: 0x0F52F982

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 454 bytes --]

  reply	other threads:[~2015-09-22  9:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-21 12:46 Set or update timestamp after evaluation of code block? Rainer M Krug
2015-09-21 13:17 ` Eric S Fraga
2015-09-21 13:42   ` Rainer M Krug
2015-09-21 14:09     ` Eric S Fraga
2015-09-21 15:15       ` Rainer M Krug
2015-09-21 15:10     ` John Kitchin
2015-09-21 18:43       ` Rainer M Krug
2015-09-21 19:27         ` John Kitchin
2015-09-22  7:52           ` Rainer M Krug
2015-09-22  9:45             ` Rainer M Krug [this message]
2015-09-21 19:53         ` Grant Rettke
2015-09-22  7:56           ` PROPERTIES attached to results blocks - Was: " Rainer M Krug
2015-09-22 15:52             ` Charles C. Berry
2015-09-21 15:37     ` Jorge A. Alfaro-Murillo
2015-09-21 18:37       ` Rainer M Krug

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=m2eghqhjof.fsf@krugs.de \
    --to=rainer@krugs.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    /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).