> > You don't need to remove the COMMENT. All you have to do is evaluate both > blocks. COMMENT only blocks exporting and expansion. It has no effect on > evaluating. > > Okay, I think I understand now. With COMMENT present, you can evaluate code blocks, but noweb refs are not expanded. So, if you evaluate the second code block, without having evaluated the first, it is indeed evaluated, but the noweb reference is not expanded hence the error. > > So, the question still remains: is this intended or not? In the docs ( https://orgmode.org/manual/Comment-Lines.html), it is stated that code blocks in commented subtrees are not exported, but it no mention is made of expansion. I couldn't find anything about this in the noweb doc ( https://orgmode.org/manual/Noweb-Reference-Syntax.html) either. >
If you take a look at, `org-babel-expand-noweb-references', you will see that it uses `org-in-commented-heading' to check if a heading is commented before it expands noweb references. So this isn’t a bug. I do think it should be better documented. > I guess one way the original problem could be solved is to tag the headline with "noexport" instead of commenting it. Not sure if that works in this case as I don't know why COMMENT was chosen over "noexport". In the case of "noexport", the docs ( https://orgmode.org/manual/Export-Settings.html) make it clear that "Even if a subtree is not exported, Org executes any code blocks contained there." Yes, the noexport tag is what you need if you want to prevent headers from exporting in a situation where you need noweb references to expand. Le dim. 28 juin 2026 à 21:24, Paul Bryan <[email protected]> a écrit : > > You don't need to remove the COMMENT. All you have to do is evaluate > both > blocks. COMMENT only blocks exporting and expansion. It has no > effect on > evaluating. > > Okay, I think I understand now. With COMMENT present, you can evaluate > code blocks, but noweb refs are not expanded. So, if you evaluate the > second code block, without having evaluated the first, it is indeed > evaluated, but the noweb reference is not expanded hence the error. > > So, the question still remains: is this intended or not? In the docs ( > https://orgmode.org/manual/Comment-Lines.html), it is stated that code > blocks in commented subtrees are not exported, but it no mention is made of > expansion. I couldn't find anything about this in the noweb doc ( > https://orgmode.org/manual/Noweb-Reference-Syntax.html) either. > > I guess one way the original problem could be solved is to tag the > headline with "noexport" instead of commenting it. Not sure if that works > in this case as I don't know why COMMENT was chosen over "noexport". In the > case of "noexport", the docs ( > https://orgmode.org/manual/Export-Settings.html) make it clear that "Even > if a subtree is not exported, Org executes any code blocks contained > there." So that's one difference. > > – Paul > > * From*: Earl Chase <earl+chase+%[email protected]%3E> > * To*: Paul Bryan <paul+bryan+%[email protected]%3E> > * Cc*: Grant Shoshin Shangreaux > <grant+shoshin+shangreaux+%[email protected]%3E> > * Date*: Sun, 28 Jun 2026 20:37:07 -0500 > * Subject*: Re: noweb expansion behavior in commented subheadings > > > > I'm guessing you mean expand and not evaluate? When I hit "C-c C-c" > on both > of the blocks in your example, they are evaluated just fine. > > > > I think the issue arises if you evaluate the second block without having > already evaluated the first block. In that case, an error is signalled: > > > > let: Symbol’s function definition is void: goo > > > > Upon removing the COMMENT from the headline and repeating, it works. Of > course, if you evaluate the first block first, it works fine in either > scenario. So it seems, as Grant pointed out, the noweb reference is not > being resolved when the surrounding headline is commented. > > > > You don't need to remove the COMMENT. All you have to do is evaluate both > blocks. COMMENT only blocks exporting and expansion. It has no effect on > evaluating. > > Le dim. 28 juin 2026 à 20:14, Paul Bryan <[email protected]> a écrit : > >> > I'm guessing you mean expand and not evaluate? When I hit "C-c C-c" on >> both > of the blocks in your example, they are evaluated just fine. >> >> I think the issue arises if you evaluate the second block *without* >> having already evaluated the first block. In that case, an error is >> signalled: >> >> let: Symbol’s function definition is void: goo >> >> Upon removing the COMMENT from the headline and repeating, it works. Of >> course, if you evaluate the first block first, it works fine in either >> scenario. So it seems, as Grant pointed out, the noweb reference is not >> being resolved when the surrounding headline is commented. >> >> I don't know the answer to whether this is intended or not, but at least >> I can say that I get the same behaviour. >> >> – *Paul* >> >> * From*: Earl Chase <earl+chase+%[email protected]%3E> >> * To*: Grant Shoshin Shangreaux >> <grant+shoshin+shangreaux+%[email protected]%3E> >> * Cc*: [email protected] >> * Date*: Sun, 28 Jun 2026 19:25:31 -0500 >> * Subject*: Re: noweb expansion behavior in commented subheadings >> >> > I stumbled upon some confusing behavior today. I am working on a >> > literate program which is published as I push commits. Some sections are >> > commented out so the won't export while I am still working on them. >> > >> > I was trying to evaluate a source block that used some noweb expansion >> > and ran into an issue where my named block was not expanding as >> > expected. Eventually I realized it was because the section I am working >> > in is commented, and the source must be skipped during expansion. >> > >> > The following demonstrates the issue (assuming you don't already have a >> > symbol named goo defined) >> > >> > * COMMENT Test Commented NoWeb >> > #+name: goo >> > #+begin_src elisp >> > (defun goo () (print "goo")) >> > #+end_src >> > >> > #+begin_src elisp :results output :noweb yes >> > <<goo>> >> > (goo) >> > #+end_src >> > >> > Is this the desired behavior? Is there a different approach to use >> > commented sections of an org-mode document while iterating with source >> > blocks? >> > >> > Thank you, >> > Grant >> > >> >> I'm guessing you mean expand and not evaluate? When I hit "C-c C-c" on >> both of the blocks in your example, they are evaluated just fine. >> >> Le dim. 28 juin 2026 à 16:05, Grant Shoshin Shangreaux >> <[email protected]> a écrit : >> >>> >>> I stumbled upon some confusing behavior today. I am working on a >>> literate program which is published as I push commits. Some sections are >>> commented out so the won't export while I am still working on them. >>> >>> I was trying to evaluate a source block that used some noweb expansion >>> and ran into an issue where my named block was not expanding as >>> expected. Eventually I realized it was because the section I am working >>> in is commented, and the source must be skipped during expansion. >>> >>> The following demonstrates the issue (assuming you don't already have a >>> symbol named goo defined) >>> >>> * COMMENT Test Commented NoWeb >>> #+name: goo >>> #+begin_src elisp >>> (defun goo () (print "goo")) >>> #+end_src >>> >>> #+begin_src elisp :results output :noweb yes >>> <<goo>> >>> (goo) >>> #+end_src >>> >>> Is this the desired behavior? Is there a different approach to use >>> commented sections of an org-mode document while iterating with source >>> blocks? >>> >>> Thank you, >>> Grant >>> >>> >>> >>> >>> >>>
