all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Matt Price <moptop99@gmail.com>
Cc: emacs list <emacs-orgmode@gnu.org>
Subject: Re: dynamic date arithmetic in a macro or otherwise (simulating a "date counter")?
Date: Wed, 23 Aug 2017 12:52:15 -0400	[thread overview]
Message-ID: <CAN_Dec9FzrbM21gNS1+9UZ0XmK8R4awKd_ETRP7S7=vysrRuWQ@mail.gmail.com> (raw)
In-Reply-To: <CAJGZZeKcE+C2fJS_jCMCZatavm58Ch+jgkQW5gpTspz_UEdEyQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2027 bytes --]

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 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

[-- Attachment #2: Type: text/html, Size: 2974 bytes --]

      parent reply	other threads:[~2017-08-23 16:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-22 23:09 dynamic date arithmetic in a macro or otherwise (simulating a "date counter")? Matt Price
2017-08-23  0:14 ` Sacha Chua
2017-08-23  2:40   ` Adam Porter
2017-08-23 16:52   ` Matt Price [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAN_Dec9FzrbM21gNS1+9UZ0XmK8R4awKd_ETRP7S7=vysrRuWQ@mail.gmail.com' \
    --to=moptop99@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.