From mboxrd@z Thu Jan 1 00:00:00 1970 From: Xebar Saram Subject: Re: Auto insert and change date in header? Date: Sun, 2 Aug 2015 21:34:40 +0300 Message-ID: References: <864nbh11z4.fsf@davemarq.austin.ibm.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=047d7b15ae45550a2c051c584e8c Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45227) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLy5r-0004oD-4y for emacs-orgmode@gnu.org; Sun, 02 Aug 2015 14:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLy5p-0002CF-KX for emacs-orgmode@gnu.org; Sun, 02 Aug 2015 14:34:43 -0400 Received: from mail-pa0-x235.google.com ([2607:f8b0:400e:c03::235]:36045) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLy5p-0002C9-95 for emacs-orgmode@gnu.org; Sun, 02 Aug 2015 14:34:41 -0400 Received: by pacgq8 with SMTP id gq8so7199941pac.3 for ; Sun, 02 Aug 2015 11:34:40 -0700 (PDT) In-Reply-To: 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: Dave Marquardt , org mode --047d7b15ae45550a2c051c584e8c Content-Type: text/plain; charset=UTF-8 Hi John i tried it by evaluating it and then it works exactly as i needed:) the only bizarre thing is that when i add it to my config emacs is frozen during startup. ive also tried adding the extra lines you suggested so now the lisp part looks like this #+BEGIN_SRC emacs-lisp (defun update-last-edited (beg end length) (when (and (not (org-before-first-heading-p)) (org-get-heading)) (org-entry-put nil "LAST-EDITED" (format-time-string "[%d-%m-%Y(%H:%M)]")))) (add-to-list 'after-change-functions 'update-last-edited) (add-hook 'org-mode-hook (lambda () (add-to-list 'after-change-functions 'update-last-edited))) #+END_SRC any idea why it freezes emacs? best Z On Sat, Aug 1, 2015 at 7:05 PM, John Kitchin wrote: > > This seems to do what you want for the changes. The timestamp is > automatically added when you make changes. It does not propagate > timestamps up though, so if you change a subheading the timestamp there > is updated, but the one in the parent for example. also, this will > update every headline. > > You may need to add another (add-hook 'org-mode-hook (lambda () > (add-to-list 'after-change-functions 'update-last-edited))) kind of line > to enable this in all org-files, the code below might be buffer local. > > #+BEGIN_SRC emacs-lisp > (defun update-last-edited (beg end length) > (when > (and > (not (org-before-first-heading-p)) > (org-get-heading)) > (org-entry-put nil "LAST-EDITED" (format-time-string "[%Y-%m-%d %a > %H:%M:%S]")))) > > (add-to-list 'after-change-functions 'update-last-edited) > #+END_SRC > > > > Xebar Saram writes: > > > Hi all > > > > coming back to it after 3 years :) > > > > im wondering if anyone has a hook or anything like that that auto adds a > > date when he creates a header. and maybe also auto change the date each > > time the text under the header is changed? kind of simulating a > timestamp > > type function :) > > > > best > > > > Z > > > > On Fri, Jul 26, 2013 at 11:49 PM, Dave Marquardt > > wrote: > > > >> Xebar Saram writes: > >> > >> > does any one know of a way to auto insert/change the date in each > >> sections > >> > header when the section is edited?IE have a date in the header showing > >> > last edited date. > >> > Is this technically possible? > >> > >> Try setting before-save-hook. See "(elisp) Saving Buffers". > >> > >> -Dave > >> > >> > >> > > -- > 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 > --047d7b15ae45550a2c051c584e8c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi John

i tried it by evaluating it and= then it works exactly as i needed:) the only bizarre thing is that when i = add it to my config emacs is frozen during startup.
ive also trie= d adding the extra lines you suggested so now the lisp part looks like this=


#+BEGIN_SRC emacs-lisp
<= div>(defun update-last-edited (beg end length)
=C2=A0 (when
=
=C2=A0 =C2=A0 =C2=A0 (and
=C2=A0 =C2=A0 =C2=A0 =C2=A0(not (o= rg-before-first-heading-p))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(org-get-h= eading))
=C2=A0 =C2=A0 (org-entry-put nil "LAST-EDITED"= (format-time-string "[%d-%m-%Y(%H:%M)]"))))

=
(add-to-list 'after-change-functions 'update-last-edited)

(add-hook 'org-mode-hook (lambda ()
(add= -to-list 'after-change-functions 'update-last-edited)))=C2=A0
=

#+END_SRC

any idea why i= t freezes emacs?

best

Z

On Sat,= Aug 1, 2015 at 7:05 PM, John Kitchin <jkitchin@andrew.cmu.edu&g= t; wrote:

This seems to do what you want for the changes. The timestamp is
automatically added when you make changes. It does not propagate
timestamps up though, so if you change a subheading the timestamp there
is updated, but the one in the parent for example. also, this will
update every headline.

You may need to add another (add-hook 'org-mode-hook (lambda ()
(add-to-list 'after-change-functions 'update-last-edited))) kind of= line
to enable this in all org-files, the code below might be buffer local.

#+BEGIN_SRC emacs-lisp
(defun update-last-edited (beg end length)
=C2=A0 (when
=C2=A0 =C2=A0 =C2=A0 (and
=C2=A0 =C2=A0 =C2=A0 =C2=A0(not (org-before-first-heading-p))
=C2=A0 =C2=A0 =C2=A0 =C2=A0(org-get-heading))
=C2=A0 =C2=A0 (org-entry-put nil "LAST-EDITED" (format-time-strin= g "[%Y-%m-%d %a %H:%M:%S]"))))

(add-to-list 'after-change-functions 'update-last-edited)
#+END_SRC



Xebar Saram writes:

> Hi all
>
> coming back to it after 3 years :)
>
> im wondering if anyone has a hook or anything like that that auto adds= a
> date when he creates a header. and maybe also auto change the date eac= h
> time=C2=A0 the text under the header is changed? kind of simulating a = timestamp
> type function :)
>
> best
>
> Z
>
> On Fri, Jul 26, 2013 at 11:49 PM, Dave Marquardt <davemarq@us.ibm.com>
> wrote:
>
>> Xebar Saram <zeltakc@gmail= .com> writes:
>>
>> > does any one know of a way to auto insert/change the date in = each
>> sections
>> > header when the section is edited?IE have a date in the heade= r showing
>> > last edited date.
>> > Is this technically possible?
>>
>> Try setting before-save-hook.=C2=A0 See "(elisp) Saving Buffe= rs".
>>
>> -Dave
>>
>>
>>

--
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

--047d7b15ae45550a2c051c584e8c--