From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Re: macro replacement in code block? Date: Wed, 01 Nov 2017 16:17:10 +0000 Message-ID: References: <17470BC7-0FB7-458A-AE92-30EC6A7A303F@therogoffs.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c07a6dcca8e40055cee341d" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43872) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vho-0005lQ-1Z for emacs-orgmode@gnu.org; Wed, 01 Nov 2017 12:17:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9vhi-0002TC-6n for emacs-orgmode@gnu.org; Wed, 01 Nov 2017 12:17:28 -0400 Received: from mail-yw0-x22e.google.com ([2607:f8b0:4002:c05::22e]:55899) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9vhi-0002T3-1O for emacs-orgmode@gnu.org; Wed, 01 Nov 2017 12:17:22 -0400 Received: by mail-yw0-x22e.google.com with SMTP id t11so2256323ywg.12 for ; Wed, 01 Nov 2017 09:17:22 -0700 (PDT) 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: David Rogoff Cc: emacs-org list --94eb2c07a6dcca8e40055cee341d Content-Type: text/plain; charset="UTF-8" On Wed, Nov 1, 2017 at 11:51 AM Kaushal Modi wrote: > I still don't have a fully working solution (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 =org-macros= block once (=C-c C-c=) - Always use that =org-macros= block to define the Org macros for this file. - Hitting =C-c C-c= 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 (=C-c C-e h o=) ===== #+BEGIN_SRC org :noweb-ref org-macros :results output replace :exports none ,#+MACRO: SEC_FOO Foo Topic ,#+MACRO: SEC_BAR Bar Topic #+END_SRC #+NAME: ehdr #+BEGIN_SRC emacs-lisp :var macro="n" :noweb yes :results raw :exports none (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 * Section 1: {{{SEC_FOO}}} #+BEGIN_SRC verilog :noweb yes <> parameter A = 1; #+END_SRC * Section 2: {{{SEC_BAR}}} #+BEGIN_SRC verilog :noweb yes <> parameter A = 1; #+END_SRC ===== -- Kaushal Modi --94eb2c07a6dcca8e40055cee341d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Wed, Nov 1,= 2017 at 11:51 AM Kaushal Modi <kaushal.modi@gmail.com> wrote:
I still d= on't have a fully working solution (see below). Hopefully someone can h= elp figure out the reason for "Invalid read syntax: #" error.

OK, I found a workaround. Be= low solution works:

1. Eval the =3Dorg-macros= =3D block once (=3DC-c C-c=3D)
=C2=A0 =C2=A0- Always use that =3D= org-macros=3D block to define the Org macros for this file.
=C2= =A0 =C2=A0- Hitting =3DC-c C-c=3D will insert those macros in this file.
=C2=A0 =C2=A0- This block is reused as a noweb-ref in other blocks.= . so keeping just this
=C2=A0 =C2=A0 =C2=A0block as a source for = all Org macros will be convenient.
2. Then export that file (=3DC= -c C-e h o=3D)

=3D=3D=3D=3D=3D
#+B= EGIN_SRC org :noweb-ref org-macros :results output replace :exports none
,#+MACRO: SEC_FOO Foo Topic
,#+MACRO: SEC_BAR Bar Top= ic
#+END_SRC

#+NAME: ehdr
= #+BEGIN_SRC emacs-lisp :var macro=3D"n" :noweb yes :results raw := exports none
(with-temp-buffer
=C2=A0 (insert "
<<org-macros>>
\n")
=C2=A0 (le= t ((start (point)))
=C2=A0 =C2=A0 (insert "// --------------= -------------\n")
=C2=A0 =C2=A0 (insert (concat "// {{{= " macro "}}}"))
=C2=A0 =C2=A0 (org-mode)
=C2=A0 =C2=A0 (org-macro-replace-all
=C2=A0 =C2=A0 =C2=A0(append= org-macro-templates org-export-global-macros))
=C2=A0 =C2=A0 (bu= ffer-substring-no-properties start (point-max))))
#+END_SRC
=

* Section 1: {{{SEC_FOO}}}
#+BEGIN_SRC verilo= g :noweb yes
<<ehdr(macro=3D"SEC_FOO")>>
parameter A =3D 1;
#+END_SRC

* S= ection 2: {{{SEC_BAR}}}
#+BEGIN_SRC verilog :noweb yes
= <<ehdr(macro=3D"SEC_BAR")>>
parameter A =3D= 1;
#+END_SRC=C2=A0
=3D=3D=3D=3D=3D
--

Kaushal Modi

--94eb2c07a6dcca8e40055cee341d--