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: David Rogoff
Subject: Re: [O] macro replacement in code block?
Date: Wed, 1 Nov 2017 10:32:14 -0700

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 
,#+MACRO: SEC_FOO 
lines out of the code block.  If I didn’t 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 / org couldn’t have a simple preproccessor-like macro :)

  David 

Sent from my iPhone

On Nov 1, 2017, at 9:17 AM, Kaushal Modi <address@hidden> wrote:

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]