Hello,

I wanted to follow up on this email. Could you provide feedback to me
please whether this is an actual bug or whether I'm using the `:noweb
tangle` option wrong. If this is unexpected behavior please let me
know if the patches I sent go in the right direction. Thanks!

Best regards,
Dominic

On Sat, Sep 6, 2025 at 2:25 PM dominic meiser <[email protected]> wrote:
>
> Hi Org Mode maintainers,
>
> I encountered what appears to be an issue with noweb reference expansion
> during tangling. I'm not sure if this is a known limitation, expected
> behavior, or if I'm misunderstanding how it should work, but I've prepared
> some patches that seem to fix the issue.
>
> The Problem:
> When using `:noweb tangle`, nested noweb references don't get recursively
> expanded. For example:
>
> #+begin_src c :tangle example.c :noweb tangle
> <<ref1>>
> <<ref2>>
> #+end_src
>
> #+begin_src c :noweb-ref ref1
> // block A content
> #+end_src
>
> #+begin_src c :noweb-ref ref2 :noweb tangle
> // block B content
> <<ref3>>
> #+end_src
>
> #+begin_src c :noweb-ref ref3
> // block C content
> #+end_src
>
> Expected: The tangled output should contain "// block C content"
> Actual: The tangled output contains the unexpanded reference "<<ref3>>"
>
> Interestingly, changing `:noweb tangle` to `:noweb yes` in the ref2 block
> makes it work, but that would also expand the reference during export,
> which I want to avoid.
>
> The Root Cause:
> The issue seems to be in `org-babel-expand-noweb-references`. When it
> recursively expands nested references, it hardcodes the context to `:eval`,
> so blocks with `:noweb tangle` don't get expanded even during tangling.
>
> The Solution:
> I've attached two patches:
> 1. Tests that demonstrate the issue and validate the fix
> 2. A minimal implementation that adds a context parameter to track whether
>    we're in `:tangle`, `:export`, or `:eval` context
>
> The fix maintains backward compatibility (the context parameter is optional
> and defaults to `:eval`).
>
> Before I submit this as a proper patch series, I wanted to check:
> - Is this the expected behavior, or is it indeed a bug?
> - If it's a bug, does this approach seem reasonable?
> - Are there any other considerations I should account for?
>
> The patches are available on my branch: `fix-noweb-tangle-recursive-expansion`
>
> Thanks for your time and for maintaining this excellent tool!
>
> Best regards,
> Dominic Meiser

Reply via email to