emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] dynamic date arithmetic in a macro or otherwise (simulating a "d


From: Matt Price
Subject: Re: [O] dynamic date arithmetic in a macro or otherwise (simulating a "date counter")?
Date: Wed, 23 Aug 2017 12:52:15 -0400



On Tue, Aug 22, 2017 at 8:14 PM, Sacha Chua <address@hidden> 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


reply via email to

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