Hi Chuck,
Thanks for your answer - I didn't know about that behavior of #+CALL, and I'm sure it will be useful sometime.
However, this is not exactly what I was getting at. Here's what I want:
1. First of all, my code needs to tangle correctly - for this I use :noweb and :noweb-ref in some of the chunks, to structure things better. org-babel-tangle produces a working source file.
2. Upon export, most source blocks should export as-they-are. However, when I use :noweb or :noweb-ref, I want two things:
a) Noweb chunk names should not be expanded upon export - e.g. <<super-duper-code>> should be exported like that
b) Chunks with :noweb-ref should be identified by their chunk name in the exported code, e.g. prepended by "<<super-duper-code>>=" in the line before the chunk name.
3. As part of the explanation in my org file, I have some other source blocks (e.g. Ditaa) which are not part of the tangle output, but rather I use to produce diagrams or other stuff. For these, I need ":exports results" behavior.
And here's my current status:
1. Works, basic org-babel functionality, no issues :)
2.a. Works by setting ":noweb no-export", no problems.
2.b. Works by modifying my exporter to include the necessary text in the exported output. *However*, the exporter can only access the :noweb-ref header argument if the =org-export-use-babel= variable is set to =nil=. Otherwise, it seems that all org-babel related headers (including :noweb, :noweb-ref and :exports) are removed from the block before it gets passed to the exporter functions.
3. Only works if =org-export-use-babel= is set to =t=, since otherwise org-babel (who does the selection of what gets exported based on :exports) never gets called.
Basically, my problem is the contradiction between (2.b) and (3) above, with respect to the org-export-use-babel variable. What I would like to know is if there is a way to keep the :noweb and :noweb-ref header arguments in the block, even after org-babel processes them.
For (2.b), I also experimented with setting =org-babel-exp-code-template=, unfortunately I encountered two problems:
1. =org-fill-template= sorts keys by length, which meant that when "%noweb-ref" appears in the template, it always gets interpreted as "%noweb" followed by the string "-ref".
2. I only want the value of :noweb-ref to be output when the parameter is specified, but =org-fill-template= doesn't handle that sort of logic - the header argument is always expanded in the template, even when its value might be missing or "no".
So, I'm still looking for a good solution to my problem. In the meantime, I can generate my Ditaa diagrams separately and just include the output in my org file, which is not tragic but not the most elegant :)
Hope this further clarifies things!
Best,
--Diego