From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Rogoff Subject: Re: macro replacement in code block? Date: Wed, 1 Nov 2017 10:32:14 -0700 Message-ID: <95C792B0-79AC-4F65-B07B-F7787D25352D@therogoffs.com> References: <17470BC7-0FB7-458A-AE92-30EC6A7A303F@therogoffs.com> Mime-Version: 1.0 (1.0) Content-Type: multipart/alternative; boundary=Apple-Mail-3D228AD8-8A5B-4086-A621-894DF9DBE129 Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9wsN-0003JG-Co for emacs-orgmode@gnu.org; Wed, 01 Nov 2017 13:32:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9wsK-0003xL-7x for emacs-orgmode@gnu.org; Wed, 01 Nov 2017 13:32:27 -0400 Received: from gproxy4-pub.mail.unifiedlayer.com ([69.89.23.142]:38087) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9wsJ-0003wg-Q4 for emacs-orgmode@gnu.org; Wed, 01 Nov 2017 13:32:24 -0400 Received: from cmgw4 (unknown [10.0.90.85]) by gproxy4.mail.unifiedlayer.com (Postfix) with ESMTP id B0066175C88 for ; Wed, 1 Nov 2017 11:32:20 -0600 (MDT) In-Reply-To: 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: Kaushal Modi Cc: emacs-org list --Apple-Mail-3D228AD8-8A5B-4086-A621-894DF9DBE129 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Thanks so much. It sort of works but with a bit of work-around: 1) tangle works fine 2) for export, I had to move the=20 > ,#+MACRO: SEC_FOO=20 lines out of the code block. If I didn=E2=80=99t and tried to eval that blo= ck, I got the error No org-babel-execute function for org! But I think this will do what I need. Of course emacs / org couldn=E2=80=99t= have a simple preproccessor-like macro :) David=20 Sent from my iPhone > On Nov 1, 2017, at 9:17 AM, Kaushal Modi wrote: >=20 >> On Wed, Nov 1, 2017 at 11:51 AM Kaushal Modi wro= te: >> I still don't have a fully working solution (see below). Hopefully someon= e can help figure out the reason for "Invalid read syntax: #" error. >=20 > OK, I found a workaround. Below solution works: >=20 > 1. Eval the =3Dorg-macros=3D block once (=3DC-c C-c=3D) > - Always use that =3Dorg-macros=3D block to define the Org macros for t= his file. > - Hitting =3DC-c C-c=3D will insert those macros in this file. > - This block is reused as a noweb-ref in other blocks.. so keeping just= this > block as a source for all Org macros will be convenient. > 2. Then export that file (=3DC-c C-e h o=3D) >=20 > =3D=3D=3D=3D=3D > #+BEGIN_SRC org :noweb-ref org-macros :results output replace :exports non= e > ,#+MACRO: SEC_FOO Foo Topic > ,#+MACRO: SEC_BAR Bar Topic > #+END_SRC >=20 > #+NAME: ehdr > #+BEGIN_SRC emacs-lisp :var macro=3D"n" :noweb yes :results raw :exports n= one > (with-temp-buffer > (insert " > <> > \n") > (let ((start (point))) > (insert "// ---------------------------\n") > (insert (concat "// {{{" macro "}}}")) > (org-mode) > (org-macro-replace-all > (append org-macro-templates org-export-global-macros)) > (buffer-substring-no-properties start (point-max)))) > #+END_SRC >=20 > * Section 1: {{{SEC_FOO}}} > #+BEGIN_SRC verilog :noweb yes > <> > parameter A =3D 1; > #+END_SRC >=20 > * Section 2: {{{SEC_BAR}}} > #+BEGIN_SRC verilog :noweb yes > <> > parameter A =3D 1; > #+END_SRC=20 > =3D=3D=3D=3D=3D > --=20 > Kaushal Modi --Apple-Mail-3D228AD8-8A5B-4086-A621-894DF9DBE129 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable Thanks so much.  It sort of works but w= ith a bit of work-around:

1) tangle works fine
=
2) for export, I had to move the 
<= span style=3D"background-color: rgba(255, 255, 255, 0);">,#+MACRO: SEC_FOO&n= bsp;
lines out of the code block. &nbs= p;If I didn=E2=80=99t and tried to eval that block, I got the error

   No org-babel-execute function for org!

But I think this will do what I need. Of course emacs / or= g couldn=E2=80=99t have a simple preproccessor-like macro :)

<= /div>
  David 

Se= nt from my iPhone

On Nov 1, 2017, at 9:17 AM, Kaushal Modi <= ;kaushal.modi@gmail.com> wr= ote:

On Wed, Nov 1, 2017 at 11:51 AM Kaushal Mo= di <kaushal.modi@gmail.com&= gt; wrote:
I still don't have a fully working solutio= n (see below). Hopefully someone can help figure out the reason for "Invalid= read syntax: #" error.

OK= , I found a workaround. Below solution works:

= 1. Eval the =3Dorg-macros=3D block once (=3DC-c C-c=3D)
  &nb= sp;- Always use that =3Dorg-macros=3D block to define the Org macros for thi= s file.
   - Hitting =3DC-c C-c=3D will insert those mac= ros in this file.
   - This block is reused as a noweb-r= ef in other blocks.. so keeping just this
     bloc= k as a source for all Org macros will be convenient.
2. Then expor= t that file (=3DC-c C-e h o=3D)

=3D=3D=3D=3D=3D=
#+BEGIN_SRC org :noweb-ref org-macros :results output replace :ex= ports none
,#+MACRO: SEC_FOO Foo Topic
,#+MACRO: SEC= _BAR Bar Topic
#+END_SRC

#+NAME: ehdr
=
#+BEGIN_SRC emacs-lisp :var macro=3D"n" :noweb yes :results raw := exports none
(with-temp-buffer
  (insert "
<<org-macros>>
\n")
  (let ((start (p= oint)))
    (insert "// ---------------------------\n")<= /div>
    (insert (concat "// {{{" macro "}}}"))
&nb= sp;   (org-mode)
    (org-macro-replace-all
     (append org-macro-templates org-export-global-macros)= )
    (buffer-substring-no-properties start (point-max))= ))
#+END_SRC

* Section 1: {{{SEC_FOO}}}
#+BEGIN_SRC verilog :noweb yes
<<ehdr(macro=3D"SEC_= FOO")>>
parameter A =3D 1;
#+END_SRC
* Section 2: {{{SEC_BAR}}}
#+BEGIN_SRC verilog :noweb y= es
<<ehdr(macro=3D"SEC_BAR")>>
parameter A =3D= 1;
#+END_SRC 
=3D=3D=3D=3D=3D
--

Kaushal Modi

= --Apple-Mail-3D228AD8-8A5B-4086-A621-894DF9DBE129--