From: "Berry, Charles" <ccberry@ucsd.edu>
To: Jarmo Hurri <jarmo.hurri@iki.fi>
Cc: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: Org src blocks and multiline macros
Date: Thu, 2 Aug 2018 16:50:12 +0000 [thread overview]
Message-ID: <6B6655B0-6A17-4A8A-AA8F-BF830D54D3D9@ucsd.edu> (raw)
In-Reply-To: <871sbhaqyu.fsf@iki.fi>
> On Aug 2, 2018, at 5:32 AM, Jarmo Hurri <jarmo.hurri@iki.fi> 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
next prev parent reply other threads:[~2018-08-02 16:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-02 6:33 Org src blocks and multiline macros Jarmo Hurri
2018-08-02 11:24 ` Kaushal Modi
2018-08-02 12:32 ` Jarmo Hurri
2018-08-02 16:50 ` Berry, Charles [this message]
2018-08-03 6:16 ` Jarmo Hurri
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=6B6655B0-6A17-4A8A-AA8F-BF830D54D3D9@ucsd.edu \
--to=ccberry@ucsd.edu \
--cc=emacs-orgmode@gnu.org \
--cc=jarmo.hurri@iki.fi \
/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).