[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Org src blocks and multiline macros
From: |
Berry, Charles |
Subject: |
Re: [O] Org src blocks and multiline macros |
Date: |
Thu, 2 Aug 2018 16:50:12 +0000 |
> On Aug 2, 2018, at 5:32 AM, Jarmo Hurri <address@hidden> wrote:
>
<Kaushal Modi replying here>
>>
>> Org macros don't get evaluated inside src blocks as far as I know. But
>> Noweb might help you. Look for this feature in Org manual. I use Noweb as
>> "macros for src blocks".
>
Me, too. But maybe Jarmo just wants a template for some text element. ??
> Yep, that will give me something similar:
>
> #+name: val1
> #+BEGIN_SRC org :exports none
> foo
> #+END_SRC
>
> #+name: val2
> #+BEGIN_SRC org :exports none
> bar
> #+END_SRC
>
> #+BEGIN_SRC org :noweb yes
> Currently this gives me ~<<val1>><<val2>>~ indeed!
> #+END_SRC
>
> Compared to multiline macros, though, having to (re)define bunch of src
> blocks for variables does seem like an overkill.
>
> BTW, does anyone know how I could enforce the standard
> Org-interpretation of '~' in the resulting, exported Org.
>
> Jarmo
There are some limitations on noweb expansion. C-c C-v C-v in a src block will
show you what the expansion looks like and how :var args are handled.
ob-org does not provide for variables AFAICS. But using emacs-lisp with a
:results drawer to render the output as org should help:
--8<---------------cut here---------------start------------->8---
#+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:
--8<---------------cut here---------------end--------------->8---
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))
See
(info "(org) Macro Replacement")
But this carries the burden of having to defun `my-really-long-macro-def'
before exporting your document.
HTH,
Chuck