emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] macro replacement in code block?


From: Kaushal Modi
Subject: Re: [O] macro replacement in code block?
Date: Wed, 01 Nov 2017 16:17:10 +0000

On Wed, Nov 1, 2017 at 11:51 AM Kaushal Modi <address@hidden> 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 "
<<org-macros>>
\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
<<ehdr(macro="SEC_FOO")>>
parameter A = 1;
#+END_SRC

* Section 2: {{{SEC_BAR}}}
#+BEGIN_SRC verilog :noweb yes
<<ehdr(macro="SEC_BAR")>>
parameter A = 1;
#+END_SRC 
=====
--

Kaushal Modi


reply via email to

[Prev in Thread] Current Thread [Next in Thread]