emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Sacha Chua <sacha@sachachua.com>
To: 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: Tue, 22 Aug 2017 20:14:11 -0400	[thread overview]
Message-ID: <CAJGZZeKcE+C2fJS_jCMCZatavm58Ch+jgkQW5gpTspz_UEdEyQ@mail.gmail.com> (raw)
In-Reply-To: <CAN_Dec8KJNW3VoCdDVn1nokWNxcQBPREyx66L3kdYo0bs_TMag@mail.gmail.com>

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

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!

On Aug 22, 2017 7:10 PM, "Matt Price" <moptop99@gmail.com> wrote:

>
>
> On Thu, Aug 17, 2017 at 3:25 PM, Matt Price <moptop99@gmail.com> wrote:
>
>> I'd love to be able generate dates dynamically using the {{{n}}} org
>> macro, or some other mechanism.  I don't immediately see how that would be
>> possible but maybe someone can guide me.  I'd want to do something
>> equivalent to this pseudo-elisp:
>>
>> (let ((base-date 2017-09-05))
>>   (+ base-date (* 7 {{{n}}}))
>>
>> I haven't looked into how date objects are parsed in org-mode, though, so
>> I have no idea how hard it would be to actually implement something like
>> this.
>>
>
> I made some progress on this (but not much).
>
> I defined a simple macro that adds times together and creates a timestamp
> that org can read -- in fact, this one adds some text as well:
>
> #+MACRO: w (eval (format-time-string "Week {{{n(week)}}} (<%Y-%m-%d %a>)"
> (time-add (encode-time 0 0 0 17 9 2017) (days-to-time (* 7 1)))) )
>
> This does everything that I want *except* dynamically adding time to the
> previous macro call.  I tried defining a dynamic version:
>
> #+MACRO: w (eval (format-time-string "Week {{{n(week)}}} (<%Y-%m-%d %a>)"
> (time-add (encode-time 0 0 0 17 9 2017) (days-to-time (* 7 $1)))) ))
>
> And then calling it with
>
> {{{w({{{n}}})}}}
>
> But unsurprisingly and appropriately, that didn't work.
>
> I also took a look at the patch Nicolas used to implement the {{{n}}}
> macro (I've reattached it here for convenience only!).  It defines
> `org-macro--counter-initialize` and calls it from inside
> `org-macro-templates-initialize`.  I guess I could copy that strategy but
> then I'd be maintaining my own copy of org-macro-templates-initialize,
> which seems like a terrible idea.
>
> So, I'm not sure how best to proceed. For my specific use-case, something
> like this would be a huge timesaver when multiplied over semesters/years.
> But I also wonder whether maybe other people would enjoy being able to do
> date arithmetic inside org files (and outside of tables -- I know from
> Sacha's 2015 blog post  that this is possible inside a table --
> http://sachachua.com/blog/2015/06/using-your-own-emacs-
> lisp-functions-in-org-mode-table-calculations-easier-dosage-totals/).  If
> other people would also use such code, I could try to hack something
> together for submission. Generalizable functions will be hard for me to
> write because I am sometimes a bit dense. I would love to hear suggestions
> from the group...
>
>
>> Thank you everyone!
>>
>
> ^^ this still applies!
> Matt
>
>

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

  reply	other threads:[~2017-08-23  0:14 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 [this message]
2017-08-23  2:40   ` Adam Porter
2017-08-23 16:52   ` Matt Price

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=CAJGZZeKcE+C2fJS_jCMCZatavm58Ch+jgkQW5gpTspz_UEdEyQ@mail.gmail.com \
    --to=sacha@sachachua.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=moptop99@gmail.com \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).