From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Price Subject: Re: Date macro - Org Mode Date: Fri, 1 Sep 2017 14:09:11 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c12ee68741048055824a87c" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59526) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dnqNX-0003k5-Ms for emacs-orgmode@gnu.org; Fri, 01 Sep 2017 14:09:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dnqNW-00054H-9J for emacs-orgmode@gnu.org; Fri, 01 Sep 2017 14:09:15 -0400 Received: from mail-pg0-x22a.google.com ([2607:f8b0:400e:c05::22a]:34299) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dnqNW-00052e-0C for emacs-orgmode@gnu.org; Fri, 01 Sep 2017 14:09:14 -0400 Received: by mail-pg0-x22a.google.com with SMTP id t193so2618624pgc.1 for ; Fri, 01 Sep 2017 11:09:12 -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" To: Jay Iyer , Org Mode --94eb2c12ee68741048055824a87c Content-Type: text/plain; charset="UTF-8" Hi Jay, I'm sorry for the long delay in writing back -- I was travelling and let my email get away from me. I'm doing something kind of similar but not exactly the same. My problem is a little bit easier -- my dates aleays change by exactly a week, so what I have done is to retain the first date and just iteratively insert timestamps as i go. So I've written this defun: (defun get-ts+7 () (interactive) (let ((base-date (save-excursion (re-search-backward (org-re-timestamp 'all)) (match-string 0))) (result nil)) (format-time-string "<%Y-%m-%d %a>" (time-add (date-to-time base-date) (days-to-time (1+ 7)))) )) Then I have an org file like: #+MACRO: ts (eval (get-ts+7)) * Week {{{n}}} <2017-09-17 Tue> * Week {{{n}}} {{{ts}}} * Week {{{n}}} {{{ts}}} * Week {{{n}}} {{{ts}}} You could modify my defun to take a parameter, maybe something like this: (defun get-ts+7 (plusdays) (interactive) (let ((base-date "<2017-09-17>") (result nil)) (format-time-string "<%Y-%m-%d %a>" (time-add (date-to-time base-date) (days-to-time (1+ plusdays)))) )) But then you'd need to eval the defun every time. So maybe something like this: #+MACRO: ts (eval (let ((base-date "<2017-09-17>")(result nil)) (format-time-string "<%Y-%m-%d %a>"(time-add (date-to-time base-date) (days-to-time (1+ plusdays)))) )) You'd have to customize the base-date value every time but maybe the above would work otherwise. I think macro definitions have to be one-liners, butm aybe not... On Sun, Aug 27, 2017 at 12:32 PM, Jay Iyer wrote: > Hi Matt, > I was wondering what is your usage of the date macro question you posted > here: http://lists.gnu.org/archive/html/emacs-orgmode/ > 2017-08/msg00605.html > > What I am trying to do is set a base date in a document and then use a > macro to define incremental dates such as "base date + n days" as the > document develops and I am wondering whether your macro would help me with > this. > > Please let me know your thoughts. > > Thanks, Matt. > -jay > > > --94eb2c12ee68741048055824a87c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Jay,

I'm sorry for th= e long delay in writing back -- I was travelling and let my email get away = from me. I'm doing something kind of similar but not exactly the same.= =C2=A0 My problem is a little bit easier -- my dates aleays change by exact= ly a week, so what I have done is to retain the first date and just iterati= vely insert timestamps as i go.=C2=A0 So I've written this defun:
=

(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 &#= 39;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=C2=A0=C2=A0=C2=A0=C2=A0 (format-time-string "<%Y-%m-= %d %a>"
=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=C2=A0=C2=A0 (time-add
=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=C2=A0=C2=A0=C2=A0 (date-to-time base-date) (= days-to-time (1+ 7)))) ))

Then I have an org file like:
=

#+MACRO: ts (eval (get-ts+7))

<= div>* Week {{{n}}} <2017-09-17 Tue>
* Week {{{n}}} {{{ts}}}=
* Week {{{n}}} {{{ts}}}
* Week {{{n}}} {{{ts}}}
<= div>

You could modify my defun to take a param= eter, maybe something like this:

(defun get-ts+7 (= plusdays)
=C2=A0=C2=A0=C2=A0 (interactive)
=C2=A0=C2=A0=C2=A0 (let ((= base-date "<2017-09-17>")
=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=C2=A0=C2=A0=C2=A0=C2=A0 (format-time-string "<%Y-%m-%d %a>&q= uot;
=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=C2= =A0=C2=A0 (time-add
=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=C2=A0=C2=A0=C2=A0 (date-to-time base-date) (days-to-time (1+ p= lusdays)))) ))

But then you'd need to eval the= defun every time. So maybe something like this:

#= +MACRO: ts (eval (let ((base-date "<2017-09-17>")(result ni= l)) (format-time-string "<%Y-%m-%d %a>"(time-add (date-to-t= ime base-date) (days-to-time (1+ plusdays)))) ))


You'd have to customize the base-date value every time but maybe t= he above would work otherwise.=C2=A0 I think macro definitions have to be o= ne-liners, butm aybe not...


On Sun, Aug 27, 2017 at 12:32 PM, Jay Iyer <= ;jayiyer09@gmail.c= om> wrote:
Hi Matt,<= /div>
I was wondering what is = your usage of the date macro question you posted here:=C2=A0http://lists.gnu.org/archive/html/emacs-orgmode/2017-= 08/msg00605.html
What I am trying to do= is set a base date in a document and then use a macro to define incrementa= l dates such as "base date + n days" as the document develops and= I am wondering whether your macro would help me with this.

Please let me know your thoughts.

Thanks, Matt.
-jay
=C2=A0


--94eb2c12ee68741048055824a87c--