emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: question about links, macros + org-publish and "parametrization"
Date: Fri, 31 May 2024 17:29:16 +0700	[thread overview]
Message-ID: <v3c8pu$kbg$1@ciao.gmane.io> (raw)
In-Reply-To: <87o78n6z0a.fsf@localhost>

On 30/05/2024 23:33, Ihor Radchenko wrote:
> Max Nikulin writes:
> 
>> I can not figure out if it is possible with some trick to expand
>> {{{year}}} before file:... is parsed.
> 
> Not possible. Macros are not recognized in verbatim contexts like link
> path.

I had in mind some technique like \expandafter in TeX or intermediate 
macro in the case of C preprocessor.

---- 8< ----
#+macro: mend }}}
#+macro: year 24
#+macro: source [[file:./$1/t.org][for the year $1]]
#+macro: target {{{source({{{year}}}){{{mend}}}

{{{source(24)}}}
{{{target}}}
{{{source({{{year}}}){{{mend}}}
---- >8 ----

It signals

     (error "Undefined Org macro: source; aborting")

during processing source code blocks. Export buffer content at this step:
---- 8< ----
#+macro: mend }}}
#+macro: year 24
#+macro: source [[file:./$1/t.org][for the year $1]]
#+macro: target {{{source({{{year}}}){{{mend}}}

[[file:./24/t.org][for the year 24]]
{{{source(24)}}}
{{{source(24)}}}
---- >8 ----

So I have almost achieved the goal despite the approach is rather 
fragile. I might work with additional pass of macro processing added as 
an extra export filter.

However I believe it is better to use either a custom link type or an 
eval macro instead of set of kludges with postponing expansion.

It is not intuitive that macro parameters are not eagerly expanded like 
function arguments in most common procedural programming languages. 
Macro languages have their own shortcomings.



  reply	other threads:[~2024-05-31 10:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-28 10:02 question about links, macros + org-publish and "parametrization" Martin Steffen
2024-05-29  8:44 ` Fraga, Eric
2024-05-30  3:52   ` Martin Steffen
2024-05-30  5:03     ` Martin Steffen
2024-05-30  8:40       ` Fraga, Eric
2024-05-30 11:25         ` Martin Steffen
2024-05-30 16:28       ` Max Nikulin
2024-05-30 16:33         ` Ihor Radchenko
2024-05-31 10:29           ` Max Nikulin [this message]
2024-05-29 13:35 ` Ihor Radchenko

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='v3c8pu$kbg$1@ciao.gmane.io' \
    --to=manikulin@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 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).