From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Berry, Charles" Subject: Re: Org src blocks and multiline macros Date: Thu, 2 Aug 2018 16:50:12 +0000 Message-ID: <6B6655B0-6A17-4A8A-AA8F-BF830D54D3D9@ucsd.edu> References: <87effhb7lu.fsf@iki.fi> <871sbhaqyu.fsf@iki.fi> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1flGnr-0007Lj-W8 for emacs-orgmode@gnu.org; Thu, 02 Aug 2018 12:50:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1flGnp-0004hu-BK for emacs-orgmode@gnu.org; Thu, 02 Aug 2018 12:50:20 -0400 Received: from iport-acv8-out.ucsd.edu ([132.239.0.21]:1031) by eggs.gnu.org with esmtps (TLS1.0:RSA_ARCFOUR_SHA1:16) (Exim 4.71) (envelope-from ) id 1flGno-0004gu-RC for emacs-orgmode@gnu.org; Thu, 02 Aug 2018 12:50:17 -0400 In-Reply-To: <871sbhaqyu.fsf@iki.fi> Content-Language: en-US Content-ID: <6E57F98444A4034D8A0ADA5CA4B57A11@AD.UCSD.EDU> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Jarmo Hurri Cc: "emacs-orgmode@gnu.org" > On Aug 2, 2018, at 5:32 AM, Jarmo Hurri wrote: >=20 >>=20 >> 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 a= s >> "macros for src blocks". >=20 Me, too. But maybe Jarmo just wants a template for some text element. ?? > Yep, that will give me something similar: >=20 > #+name: val1 > #+BEGIN_SRC org :exports none > foo > #+END_SRC >=20 > #+name: val2 > #+BEGIN_SRC org :exports none > bar > #+END_SRC >=20 > #+BEGIN_SRC org :noweb yes > Currently this gives me ~<><>~ indeed! > #+END_SRC >=20 > Compared to multiline macros, though, having to (re)define bunch of src > blocks for variables does seem like an overkill. >=20 > BTW, does anyone know how I could enforce the standard > Org-interpretation of '~' in the resulting, exported Org. >=20 > Jarmo There are some limitations on noweb expansion. C-c C-v C-v in a src block w= ill 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=3D"foo" :var val2=3D"bar"=20 (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 possibil= ity 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' b= efore exporting your document. =20 HTH, Chuck