emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Org src blocks and multiline macros


From: Jarmo Hurri
Subject: Re: [O] Org src blocks and multiline macros
Date: Fri, 03 Aug 2018 09:16:41 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

"Berry, Charles" <address@hidden> writes:

> ob-org does not provide for variables AFAICS. 

I have been trying to advocate for multiline macros for years, because
those are the _only_ thing I am really missing in org, again and
again. For example, right now I am writing teaching material where I
need to reuse certain parametrised org snippets across multiple files. I
_could_ use noweb. I _could_ use elisp code. But having a tool similar
to \newcommand in Latex would be so useful that every once in a while I
find myself bringing it up again.

The latest idea was to introduce variables into org blocks in hope it
would implement the desired functionality

> But using emacs-lisp with a :results drawer to render the output as
> org should help:
>
> #+header: :results drawer :exports results
> #+begin_src emacs-lisp :var val1="foo" :var val2="bar" 
>    (concat "Currently this gives me ~" val1 val2 "~ indeed!")
> #+END_SRC
>
> #+RESULTS:
> :results:
> Currently this gives me ~foobar~ indeed!
> :end:

Ok, this will work too. But my real document string contains multiple
paragraphs, org lists etc. In terms of readability and maintainability,
embedding that text as an argument in an elisp call is not a very clean
solution.

> BTW, if you really do need a long or multiline MACRO, there is the
> possibility of using an `eval' style macro with a custom elisp
> function. e.g.
>
> #+MACRO: longish-macro (eval (my-really-long-macro-def $1 $2 $3))
>
> (info "(org) Macro Replacement")
>
> But this carries the burden of having to defun
> `my-really-long-macro-def' before exporting your document.

Yes, this too will work, with similar reservations as in the previous
case.

Thanks for all the tips!

Jarmo




reply via email to

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