emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Date macro - Org Mode


From: Matt Price
Subject: Re: [O] Date macro - Org Mode
Date: Fri, 1 Sep 2017 14:09:11 -0400

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 <address@hidden> 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
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]