I still don't have a fully working solution (see below). Hopefully someone can help figure out the reason for "Invalid read syntax: #" error.
Below example Org file will work right away. But it will fail with the above error the moment second line (for more macros) is added to org-macros block.
Here's a minimal working example to recreate that specific problem:
- The problem is seen when you C-c C-c the "noworky" block.
=====
#+BEGIN_SRC org :noweb-ref org-macros-1-line :results output replace :exports none
,#+MACRO: AA 1
#+END_SRC
#+RESULTS:
#+MACRO: AA 1
#+BEGIN_SRC org :noweb-ref org-macros-2-lines :results output replace :exports none
,#+MACRO: BB 2
,#+MACRO: CC 3
#+END_SRC
#+RESULTS:
#+MACRO: BB 2
#+MACRO: CC 3
* This works
#+NAME: works
#+BEGIN_SRC emacs-lisp :var macro="AA" :noweb yes :results raw :exports none
(with-temp-buffer
(insert "<<org-macros-1-line>>\n")
(insert (concat "{{{" macro "}}}"))
(org-mode)
(org-macro-replace-all
(append org-macro-templates org-export-global-macros))
(buffer-substring-no-properties (point-min) (point-max)))
#+END_SRC
#+CALL: works()
* This does not work
#+NAME: noworky
#+BEGIN_SRC emacs-lisp :var macro="BB" :noweb yes :results raw :exports none
(with-temp-buffer
(insert "<<org-macros-2-lines>>\n")
(insert "// ---------------------------\n")
(insert (concat "{{{" macro "}}}"))
(org-mode)
(org-macro-replace-all
(append org-macro-templates org-export-global-macros))
(buffer-substring-no-properties (point-min) (point-max)))
#+END_SRC
If you uncomment the below =#+CALL= line, you will get:
#+BEGIN_EXAMPLE
org-babel-execute:emacs-lisp: Invalid read syntax: "#"
#+END_EXAMPLE
when you try to export (or even if you =C-c C-c= that =noworky= block.
# #+CALL: noworky()
=====