emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* nested macro expansion?
@ 2015-08-19 11:28 Eric Abrahamsen
  2015-08-19 11:33 ` Eric Abrahamsen
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Abrahamsen @ 2015-08-19 11:28 UTC (permalink / raw)
  To: emacs-orgmode

What I'm trying to do is have a macro that takes the computed TIMESTAMP
property for an entry, and then runs it through a custom function that
breaks out the start/end times, and produces a nicely formatted string
from that.

I don't see how to write a macro that feeds the value of a computed
special property to a function.

Right now my testing version looks like this:

#+MACRO: bubba (eval (format-time-string "%Y" "$1"))

and I'm calling it like this:

{{{bubba({{{property(TIMESTAMP)}}})}}}

That doesn't expand the interior "{{{property(TIMESTAMP)}}}" clause.
What `format-time-string' ends up seeing is "{{{property(TIMESTAMP",
without the final braces etc.

Is there any way to get that value expanded first, and then passed to
`format-time-string' (or, eventually, my custom function)?

Thanks!

Eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: nested macro expansion?
  2015-08-19 11:28 nested macro expansion? Eric Abrahamsen
@ 2015-08-19 11:33 ` Eric Abrahamsen
  2015-08-19 14:43   ` Pip Cet
  2015-08-19 20:18   ` Nicolas Goaziou
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2015-08-19 11:33 UTC (permalink / raw)
  To: emacs-orgmode

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> What I'm trying to do is have a macro that takes the computed TIMESTAMP
> property for an entry, and then runs it through a custom function that
> breaks out the start/end times, and produces a nicely formatted string
> from that.
>
> I don't see how to write a macro that feeds the value of a computed
> special property to a function.
>
> Right now my testing version looks like this:
>
> #+MACRO: bubba (eval (format-time-string "%Y" "$1"))
>
> and I'm calling it like this:
>
> {{{bubba({{{property(TIMESTAMP)}}})}}}
>
> That doesn't expand the interior "{{{property(TIMESTAMP)}}}" clause.
> What `format-time-string' ends up seeing is "{{{property(TIMESTAMP",
> without the final braces etc.
>
> Is there any way to get that value expanded first, and then passed to
> `format-time-string' (or, eventually, my custom function)?

After googling for a while, I also thought this might work:

#+MACRO: bubba (eval (format-time-string "%Y" property{{{TIMESTAMP}}}))

{{{bubba}}}

But the nested definition isn't expanded, either with or without quotes.

E

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: nested macro expansion?
  2015-08-19 11:33 ` Eric Abrahamsen
@ 2015-08-19 14:43   ` Pip Cet
  2015-08-19 15:03     ` Eric Abrahamsen
  2015-08-19 20:18   ` Nicolas Goaziou
  1 sibling, 1 reply; 6+ messages in thread
From: Pip Cet @ 2015-08-19 14:43 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hi Eric,
I know this doesn't answer your actual question about nested macro
expansion, but writing some elisp might help you get the TIMESTAMP
property, at least: both

#+MACRO: bubba (eval (org-entry-get nil "TIMESTAMP"))

and

#+MACRO: bubba (eval (org-macro-expand "{{{property(TIMESTAMP)}}}"
org-macro-templates))

appear to produce the current timestamp, and both can be fed to
another function, but not `format-time-string': the result of
(org-entry-get...) is a string of the form "<2014-08-19>", which would
need to be passed to `org-parse-time-string' first.

On 8/19/15, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> What I'm trying to do is have a macro that takes the computed TIMESTAMP
>> property for an entry, and then runs it through a custom function that
>> breaks out the start/end times, and produces a nicely formatted string
>> from that.
>>
>> I don't see how to write a macro that feeds the value of a computed
>> special property to a function.
>>
>> Right now my testing version looks like this:
>>
>> #+MACRO: bubba (eval (format-time-string "%Y" "$1"))
>>
>> and I'm calling it like this:
>>
>> {{{bubba({{{property(TIMESTAMP)}}})}}}
>>
>> That doesn't expand the interior "{{{property(TIMESTAMP)}}}" clause.
>> What `format-time-string' ends up seeing is "{{{property(TIMESTAMP",
>> without the final braces etc.
>>
>> Is there any way to get that value expanded first, and then passed to
>> `format-time-string' (or, eventually, my custom function)?
>
> After googling for a while, I also thought this might work:
>
> #+MACRO: bubba (eval (format-time-string "%Y" property{{{TIMESTAMP}}}))
>
> {{{bubba}}}
>
> But the nested definition isn't expanded, either with or without quotes.
>
> E
>
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: nested macro expansion?
  2015-08-19 14:43   ` Pip Cet
@ 2015-08-19 15:03     ` Eric Abrahamsen
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2015-08-19 15:03 UTC (permalink / raw)
  To: Pip Cet; +Cc: emacs-orgmode


On 08/19/15 14:43 PM, Pip Cet wrote:
> Hi Eric,
> I know this doesn't answer your actual question about nested macro
> expansion, but writing some elisp might help you get the TIMESTAMP
> property, at least: both
>
> #+MACRO: bubba (eval (org-entry-get nil "TIMESTAMP"))
>
> and
>
> #+MACRO: bubba (eval (org-macro-expand "{{{property(TIMESTAMP)}}}"
> org-macro-templates))
>
> appear to produce the current timestamp, and both can be fed to
> another function, but not `format-time-string': the result of
> (org-entry-get...) is a string of the form "<2014-08-19>", which would
> need to be passed to `org-parse-time-string' first.

Hey, that does the trick, thank you! I guess I should have thought of
that.

Sure, the example as I gave it would have errored had it done anything,
but the main thing was just getting the right values in the right place.
Off to write the function...

Thanks again,
Eric

> On 8/19/15, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:
>> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>
>>> What I'm trying to do is have a macro that takes the computed TIMESTAMP
>>> property for an entry, and then runs it through a custom function that
>>> breaks out the start/end times, and produces a nicely formatted string
>>> from that.
>>>
>>> I don't see how to write a macro that feeds the value of a computed
>>> special property to a function.
>>>
>>> Right now my testing version looks like this:
>>>
>>> #+MACRO: bubba (eval (format-time-string "%Y" "$1"))
>>>
>>> and I'm calling it like this:
>>>
>>> {{{bubba({{{property(TIMESTAMP)}}})}}}
>>>
>>> That doesn't expand the interior "{{{property(TIMESTAMP)}}}" clause.
>>> What `format-time-string' ends up seeing is "{{{property(TIMESTAMP",
>>> without the final braces etc.
>>>
>>> Is there any way to get that value expanded first, and then passed to
>>> `format-time-string' (or, eventually, my custom function)?
>>
>> After googling for a while, I also thought this might work:
>>
>> #+MACRO: bubba (eval (format-time-string "%Y" property{{{TIMESTAMP}}}))
>>
>> {{{bubba}}}
>>
>> But the nested definition isn't expanded, either with or without quotes.
>>
>> E
>>
>>
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: nested macro expansion?
  2015-08-19 11:33 ` Eric Abrahamsen
  2015-08-19 14:43   ` Pip Cet
@ 2015-08-19 20:18   ` Nicolas Goaziou
  2015-08-20  1:24     ` Eric Abrahamsen
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2015-08-19 20:18 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hello

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> After googling for a while, I also thought this might work:
>
> #+MACRO: bubba (eval (format-time-string "%Y" property{{{TIMESTAMP}}}))
>
> {{{bubba}}}
>
> But the nested definition isn't expanded, either with or without
> quotes.

As you noticed, you cannot nest macros. You can use macros within macro
definitions, tho. Alas, it will not work with (eval ...) templates,
since those make no assumptions about the rest of the template and
simply use `read' on it.

Anyway, as pointed out in this thread, if you take the (eval ...) path,
you don't really need macros: you're in Elisp.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: nested macro expansion?
  2015-08-19 20:18   ` Nicolas Goaziou
@ 2015-08-20  1:24     ` Eric Abrahamsen
  0 siblings, 0 replies; 6+ messages in thread
From: Eric Abrahamsen @ 2015-08-20  1:24 UTC (permalink / raw)
  To: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello
>
> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> After googling for a while, I also thought this might work:
>>
>> #+MACRO: bubba (eval (format-time-string "%Y" property{{{TIMESTAMP}}}))
>>
>> {{{bubba}}}
>>
>> But the nested definition isn't expanded, either with or without
>> quotes.
>
> As you noticed, you cannot nest macros. You can use macros within macro
> definitions, tho. Alas, it will not work with (eval ...) templates,
> since those make no assumptions about the rest of the template and
> simply use `read' on it.
>
> Anyway, as pointed out in this thread, if you take the (eval ...) path,
> you don't really need macros: you're in Elisp.

Thanks to both of you for the pointers! This is my first time trying to
do anything non-trivial with macros, and the orientation is very useful.

Eric

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-08-20  1:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-19 11:28 nested macro expansion? Eric Abrahamsen
2015-08-19 11:33 ` Eric Abrahamsen
2015-08-19 14:43   ` Pip Cet
2015-08-19 15:03     ` Eric Abrahamsen
2015-08-19 20:18   ` Nicolas Goaziou
2015-08-20  1:24     ` Eric Abrahamsen

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