From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rainer M Krug Subject: Re: Set or update timestamp after evaluation of code block? Date: Tue, 22 Sep 2015 11:45:04 +0200 Message-ID: References: <87pp1bsyhn.fsf@ucl.ac.uk> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46941) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeK8S-00088Y-Fy for emacs-orgmode@gnu.org; Tue, 22 Sep 2015 05:45:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZeK8P-0008QO-8H for emacs-orgmode@gnu.org; Tue, 22 Sep 2015 05:45:16 -0400 Received: from mail-wi0-f170.google.com ([209.85.212.170]:36097) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeK8O-0008Q2-V1 for emacs-orgmode@gnu.org; Tue, 22 Sep 2015 05:45:13 -0400 Received: by wicgb1 with SMTP id gb1so151381905wic.1 for ; Tue, 22 Sep 2015 02:45:12 -0700 (PDT) In-Reply-To: (Rainer M. Krug's message of "Tue, 22 Sep 2015 09:52:30 +0200") 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: John Kitchin Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Rainer M Krug writes: > John Kitchin 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=3Dcan I somehow jump to the beginning of the code block when I am in a preceding #+ line? Thanks, Rainer =2D-8<---------------cut here---------------start------------->8--- #+LASTRUN: [2015-09-22 Tue 11:37:43] #+begin_src emacs-lisp=20 (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 =2D-8<---------------cut here---------------end--------------->8--- > > Thanks a lot, > > Rainer > >> >> >> Rainer M Krug writes: >> >>> John Kitchin writes: >>> >>>> Here is one approach: >>>> >>>> #+name: update-timestamp >>>> #+BEGIN_SRC emacs-lisp :var data=3D"" >>>> (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=3D*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 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 alre= ady) >>>>>>> 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 bl= ock >>>>> invalid. >>>>> >>>>> How can I put the time stamp in the line after the #+end_src or possi= bly >>>>> 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 =2D-=20 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 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBCAAGBQJWASMlAAoJENvXNx4PUvmCRuQH/Amv2OnaeYxEpv5m+vUIWqTt BKaCiPtQlFX5B19pGwqIZj+qo4XR//c4Qg9iiC8NF+4sqQr0rsMvEQjvkVgHtO2m Q5CaCQbiZ8R1DyZC3sSidGCx96HkJ+G4jQJwNQ0QJMro/M6aN5BUkqNACev9+8fd mJk++E1mnOjLKrydpPiL3hGREV6BONRW+eLdZP++u5veGEuF1FoSsExDJ5oC369I jkeCMtorUdx1BWxxQ2Nb3kGP8C8NAllJCzD1SJAXGazLyAM9W6bLXnMb+yiMd6Ba bYTnEH7EtGQPmwoQJwUfPKKwGU6RicbYJ7TQYBVzm8Ah5RsXZlM3SaxQw1uURNE= =CJ1i -----END PGP SIGNATURE----- --=-=-=--