From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin <jkitchin@andrew.cmu.edu> Subject: Re: Auto insert and change date in header? Date: Sun, 2 Aug 2015 20:09:06 -0400 Message-ID: <CAJ51ETpfp3N3fPz+1CLZC64y6R6kGX7AKW3FsZtOsnM3BUwUqA@mail.gmail.com> References: <CAOQHXPo6G_tJRjZ=K1DZdsxDO94RBg7ANDW96yaiYP62Z8FHyw@mail.gmail.com> <864nbh11z4.fsf@davemarq.austin.ibm.com> <CAOQHXPpPM_OM9ZDUoLtWkoud6qHP_Gy6Zaihs9kazXnvHXh-7g@mail.gmail.com> <m24mkj0zbb.fsf@andrew.cmu.edu> <CAOQHXPqW_UYR84Za5KahQZTLnvXOPqdyKUPzxoroNWB2YC4QPw@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c3871a5d8456051c5cfa84 Return-path: <emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org> Received: from eggs.gnu.org ([2001:4830:134:3::10]:37046) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <johnrkitchin@gmail.com>) id 1ZM3JV-0000Ny-0S for emacs-orgmode@gnu.org; Sun, 02 Aug 2015 20:09:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <johnrkitchin@gmail.com>) id 1ZM3JT-00077V-IE for emacs-orgmode@gnu.org; Sun, 02 Aug 2015 20:09:08 -0400 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:33135) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <johnrkitchin@gmail.com>) id 1ZM3JT-00077J-6z for emacs-orgmode@gnu.org; Sun, 02 Aug 2015 20:09:07 -0400 Received: by wicmv11 with SMTP id mv11so115440989wic.0 for <emacs-orgmode@gnu.org>; Sun, 02 Aug 2015 17:09:06 -0700 (PDT) In-Reply-To: <CAOQHXPqW_UYR84Za5KahQZTLnvXOPqdyKUPzxoroNWB2YC4QPw@mail.gmail.com> List-Id: "General discussions about Org-mode." <emacs-orgmode.gnu.org> List-Unsubscribe: <https://lists.gnu.org/mailman/options/emacs-orgmode>, <mailto:emacs-orgmode-request@gnu.org?subject=unsubscribe> List-Archive: <http://lists.gnu.org/archive/html/emacs-orgmode> List-Post: <mailto:emacs-orgmode@gnu.org> List-Help: <mailto:emacs-orgmode-request@gnu.org?subject=help> List-Subscribe: <https://lists.gnu.org/mailman/listinfo/emacs-orgmode>, <mailto:emacs-orgmode-request@gnu.org?subject=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: Xebar Saram <zeltakc@gmail.com> Cc: Dave Marquardt <davemarq@us.ibm.com>, org mode <emacs-orgmode@gnu.org> --001a11c3871a5d8456051c5cfa84 Content-Type: text/plain; charset=UTF-8 you probably only need this: (add-hook 'org-mode-hook (lambda () (add-to-list 'after-change-functions 'update-last-edited))) and not this: (add-to-list 'after-change-functions 'update-last-edited) I guess that this last line could be causing an issue in buffers like *Messages* which change a lot, especially during startup. John ----------------------------------- 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 On Sun, Aug 2, 2015 at 2:34 PM, Xebar Saram <zeltakc@gmail.com> wrote: > 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 <jkitchin@andrew.cmu.edu> > 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 <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 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 >> > > --001a11c3871a5d8456051c5cfa84 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">=C2=A0you probably only need this:<div><br></div><div><div= style=3D"color:rgb(80,0,80);font-size:13px">(add-hook 'org-mode-hook (= lambda ()</div><div style=3D"color:rgb(80,0,80);font-size:13px">(add-to-lis= t 'after-change-functions 'update-last-edited)))=C2=A0</div></div><= div style=3D"color:rgb(80,0,80);font-size:13px"><br></div><div style=3D"col= or:rgb(80,0,80);font-size:13px">and not this:</div><div style=3D"color:rgb(= 80,0,80);font-size:13px"><br></div><div style=3D"color:rgb(80,0,80);font-si= ze:13px"><span style=3D"color:rgb(34,34,34)">(add-to-list 'after-change= -functions 'update-last-edited)</span><br></div><div style=3D"color:rgb= (80,0,80);font-size:13px"><span style=3D"color:rgb(34,34,34)"><br></span></= div><div style=3D"color:rgb(80,0,80);font-size:13px"><span style=3D"color:r= gb(34,34,34)">I guess that this last line could be causing an issue in buff= ers like *Messages* which change a lot, especially during startup.</span></= div><div style=3D"color:rgb(80,0,80);font-size:13px"><br></div></div><div c= lass=3D"gmail_extra"><br clear=3D"all"><div><div class=3D"gmail_signature">= <div dir=3D"ltr"><div><div dir=3D"ltr">John<br><br>------------------------= -----------<br>Professor John Kitchin=C2=A0<br>Doherty Hall A207F<br>Depart= ment of Chemical Engineering<br>Carnegie Mellon University<br>Pittsburgh, P= A 15213<br>412-268-7803</div><div dir=3D"ltr">@johnkitchin<br><a href=3D"ht= tp://kitchingroup.cheme.cmu.edu" target=3D"_blank">http://kitchingroup.chem= e.cmu.edu</a><br><br></div></div></div></div></div> <br><div class=3D"gmail_quote">On Sun, Aug 2, 2015 at 2:34 PM, Xebar Saram = <span dir=3D"ltr"><<a href=3D"mailto:zeltakc@gmail.com" target=3D"_blank= ">zeltakc@gmail.com</a>></span> wrote:<br><blockquote class=3D"gmail_quo= te" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"= ><div dir=3D"ltr">Hi John<div><br></div><div>i tried it by evaluating it an= d 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.</div><div>ive also tri= ed adding the extra lines you suggested so now the lisp part looks like thi= s</div><div><br></div><div><span class=3D""><div><br></div><div>#+BEGIN_SRC= emacs-lisp</div><div>(defun update-last-edited (beg end length)</div><div>= =C2=A0 (when</div><div>=C2=A0 =C2=A0 =C2=A0 (and</div><div>=C2=A0 =C2=A0 = =C2=A0 =C2=A0(not (org-before-first-heading-p))</div><div>=C2=A0 =C2=A0 =C2= =A0 =C2=A0(org-get-heading))</div></span><div>=C2=A0 =C2=A0 (org-entry-put = nil "LAST-EDITED" (format-time-string "[%d-%m-%Y(%H:%M)]&quo= t;))))</div><div><br></div><div>(add-to-list 'after-change-functions &#= 39;update-last-edited)</div><span class=3D""><div><br></div><div>(add-hook = 'org-mode-hook (lambda ()</div><div>(add-to-list 'after-change-func= tions 'update-last-edited)))=C2=A0</div><div><br></div></span><div>#+EN= D_SRC</div></div><div><br></div><div>any idea why it freezes emacs?</div><d= iv><br></div><div>best</div><div><br></div><div>Z</div></div><div class=3D"= HOEnZb"><div class=3D"h5"><div class=3D"gmail_extra"><br><div class=3D"gmai= l_quote">On Sat, Aug 1, 2015 at 7:05 PM, John Kitchin <span dir=3D"ltr"><= ;<a href=3D"mailto:jkitchin@andrew.cmu.edu" target=3D"_blank">jkitchin@andr= ew.cmu.edu</a>></span> wrote:<br><blockquote class=3D"gmail_quote" style= =3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br> This seems to do what you want for the changes. The timestamp is<br> automatically added when you make changes. It does not propagate<br> timestamps up though, so if you change a subheading the timestamp there<br> is updated, but the one in the parent for example. also, this will<br> update every headline.<br> <br> You may need to add another (add-hook 'org-mode-hook (lambda ()<br> (add-to-list 'after-change-functions 'update-last-edited))) kind of= line<br> to enable this in all org-files, the code below might be buffer local.<br> <br> #+BEGIN_SRC emacs-lisp<br> (defun update-last-edited (beg end length)<br> =C2=A0 (when<br> =C2=A0 =C2=A0 =C2=A0 (and<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0(not (org-before-first-heading-p))<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-get-heading))<br> =C2=A0 =C2=A0 (org-entry-put nil "LAST-EDITED" (format-time-strin= g "[%Y-%m-%d %a %H:%M:%S]"))))<br> <br> (add-to-list 'after-change-functions 'update-last-edited)<br> #+END_SRC<br> <div><div><br> <br> <br> Xebar Saram writes:<br> <br> > Hi all<br> ><br> > coming back to it after 3 years :)<br> ><br> > im wondering if anyone has a hook or anything like that that auto adds= a<br> > date when he creates a header. and maybe also auto change the date eac= h<br> > time=C2=A0 the text under the header is changed? kind of simulating a = timestamp<br> > type function :)<br> ><br> > best<br> ><br> > Z<br> ><br> > On Fri, Jul 26, 2013 at 11:49 PM, Dave Marquardt <<a href=3D"mailto= :davemarq@us.ibm.com" target=3D"_blank">davemarq@us.ibm.com</a>><br> > wrote:<br> ><br> >> Xebar Saram <<a href=3D"mailto:zeltakc@gmail.com" target=3D"_bl= ank">zeltakc@gmail.com</a>> writes:<br> >><br> >> > does any one know of a way to auto insert/change the date in = each<br> >> sections<br> >> > header when the section is edited?IE have a date in the heade= r showing<br> >> > last edited date.<br> >> > Is this technically possible?<br> >><br> >> Try setting before-save-hook.=C2=A0 See "(elisp) Saving Buffe= rs".<br> >><br> >> -Dave<br> >><br> >><br> >><br> <br> </div></div>--<br> Professor John Kitchin<br> Doherty Hall A207F<br> Department of Chemical Engineering<br> Carnegie Mellon University<br> Pittsburgh, PA 15213<br> <a href=3D"tel:412-268-7803" value=3D"+14122687803" target=3D"_blank">412-2= 68-7803</a><br> @johnkitchin<br> <a href=3D"http://kitchingroup.cheme.cmu.edu" rel=3D"noreferrer" target=3D"= _blank">http://kitchingroup.cheme.cmu.edu</a><br> </blockquote></div><br></div> </div></div></blockquote></div><br></div> --001a11c3871a5d8456051c5cfa84--