From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: dynamic date arithmetic in a macro or otherwise (simulating a "date counter")? Date: Wed, 23 Aug 2017 12:52:15 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="f40304361924bf4e6e05576e88b8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dkYt8-0008Px-TY for emacs-orgmode@gnu.org; Wed, 23 Aug 2017 12:52:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dkYt7-0005up-N8 for emacs-orgmode@gnu.org; Wed, 23 Aug 2017 12:52:18 -0400 Received: from mail-pg0-x22f.google.com ([2607:f8b0:400e:c05::22f]:38345) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dkYt7-0005uf-Ep for emacs-orgmode@gnu.org; Wed, 23 Aug 2017 12:52:17 -0400 Received: by mail-pg0-x22f.google.com with SMTP id m133so2260765pga.5 for ; Wed, 23 Aug 2017 09:52:17 -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" Cc: emacs list --f40304361924bf4e6e05576e88b8 Content-Type: text/plain; charset="UTF-8" On Tue, Aug 22, 2017 at 8:14 PM, Sacha Chua wrote: > org-clone-subtree-with-time-shift might be a good starting point, too. It > could be interesting to be able to replace dates within text and > priorities. Good luck! > Interesting, I didn't know about `org-clone-subtree-with-time-shjift`. thank you. So, cloning isn't necessarily what I'm looking for; I'm often working with documents that need to be largely reused with modifications. That means that abo-abo's tiny isn't quite right for me, either. So I've written the following; it still feels really clumsy but it seems to work for now! It's loosely based on some code that Jon Kitchin wrote for me on this list about 2 years ago (!!). Here it is: #+MACRO: ts (eval (get-ts+7)) #+BEGIN_SRC emacs-lisp (defun get-ts+7 () (interactive) (let ((base-date (save-excursion (re-search-backward (org-re-timestamp 'all)) (match-string 0))) (result nil)) (with-temp-buffer (org-mode) (insert base-date ) (backward-char) (org-timestamp-change 7 'day) (end-of-buffer) (insert " ") (end-of-buffer) (setq result (save-excursion (re-search-backward (org-re-timestamp 'all)) (match-string 0)))) result)) #+END_SRC There's no error-checking, but basically you just insert the date of the first weekly meeting and all the other dates update themselves automatically on export. It's pretty cool. One next step would be to allow more complex repetition cycles (e.g., to repeat eveyr tuesday and thursday, or monday Wednesday Friday, etc.). So now my headlines all just look like this: ** Week {{{n}}} ({{{ts}}}): Topic Still working on that tree merge idea, will check back in on that other thread if I get anywhere with it. Thanks to both Adam and Sacha for the help! I'd love to hear any other suggestions people might have. Matt --f40304361924bf4e6e05576e88b8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, Aug 22, 2017 at 8:14 PM, Sacha Chua <sacha@sachachua.com= > wrote:
org-clone-subtree-with-time-shift might be a good start= ing point, too. It could be interesting to be able to replace dates within = text and priorities. Good luck!

Inter= esting, I didn't know about `org-clone-subtree-with-time-shjift`.=C2=A0= thank you.=C2=A0

So, cloning isn't neces= sarily what I'm looking for; I'm often working with documents that = need to be largely reused with modifications. That means that abo-abo's= tiny isn't quite right for me, either.=C2=A0 So I've written the f= ollowing; it still feels really clumsy but it seems to work for now! It'= ;s loosely based on some code that Jon Kitchin wrote for me on this list ab= out 2 years ago (!!). Here it is:

#+MACRO: ts (eva= l (get-ts+7))


#+BEGIN_SRC emacs-lisp
= =C2=A0 =C2=A0 (defun get-ts+7 ()
=C2=A0=C2=A0=C2=A0 (interactive)
=C2= =A0=C2=A0=C2=A0 (let ((base-date (save-excursion
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= (re-search-backward
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org-re-timestamp '= all))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (match-string 0)))
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (result nil))
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 (with-temp-buffer
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org= -mode)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (insert base-date )=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (backward-char)
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org-timestamp-change 7 'day)
=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (end-of-buffer)
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (insert "=C2=A0 ")
=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (end-of-buffer)
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (setq result (save-excursion
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 (re-search-backward
=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (org-re-timestamp 'all))
=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (match-string 0))))<= br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 result))
#+END_SRC

<= /div>
There's no error-checking, but basically you just insert the = date of the first weekly meeting and all the other dates update themselves = automatically on export.=C2=A0 It's pretty cool.=C2=A0 One next step wo= uld be to allow more complex repetition cycles (e.g., to repeat eveyr tuesd= ay and thursday, or monday Wednesday Friday, etc.).=C2=A0
So now my headlines all just look like this:

** Week {{{n}}} ({{{ts}}}): Topic

Still wo= rking on that tree merge idea, will check back in on that other thread if I= get anywhere with it.=C2=A0

Thanks to both A= dam and Sacha for the help! I'd love to hear any other suggestions peop= le might have.

Matt

--f40304361924bf4e6e05576e88b8--