Hi,

Thank you for reading the lengthy doc and giving the suggestions!

> Also, the example you provide about noweb prefix, might be problematic.
> In the example "hello" is not preceded by the prefix, which may break
> the tangling for indentation-sensitive languages like python.
> 
> #+begin_src emacs-lisp :tangle case-analysis.el :noweb yes :comments noweb 
> :noweb-prefix no
> before
> prefix <<a string>> in between <<a string>> suffix
> after
> #+end_src
> 
> tangles to
> 
> #+begin_src emacs-lisp
> ;; [[file:org-babel-detangle.org::*Two references in a row][Two references in 
> a row:1]]
> before
> prefix ;; [[file:org-babel-detangle.org::*Two references in a row][a string]]
> "hello"

Regarding this part, I totally agree that Noweb prefix can be gnarly when used 
with =:comments noweb=.  Though I believe this is the *correct* behavior, the 
user should definitely use it *with care*.  In fact, this is what happens under 
the current Org version, rather than something resulted from my patch, and I 
kinda understand and agree with it.

Basically, when tangled without =:comments noweb=, the result would be:

> #+begin_src emacs-lisp
> before
> prefix "hello" suffix
> after
> #+end_src

Notice that =prefix "hello" suffix= are at the same line, so everything is fine 
if =prefix= has the correct indentation.  However, since Noweb comments need to 
take a new line (otherwise everything would be commented out), tangling with 
them make the three parts each live in a separate line.  The consequence is 
that, when =:noweb-prefix no=, we lose the indentation for ="hello"= and 
=suffix=.  As a consequence, Python users should be extremely careful when 
using =:noweb-prefix no= with =:comments noweb= (e.g., it's still fine to 
write: ~print(<<a string>>)~).

I totally understand and have the same concern on usability, but I guess given 
the rich feature set of Noweb in Org mode (especially the quirky Noweb prefix 
stuffs), such feature interaction problem is inevitable, and we unfortunately 
may have to live with it.

Thanks again,
MT

On Sat, Nov 22, 2025, at 05:41, Ihor Radchenko wrote:
> MT <[email protected]> writes:
> 
> > I've just completed a rewrite of the Org Babel detangling facility.  The 
> > work should give a *full support* of detangling with Noweb references.  The 
> > the actual code (along with the motivation, design, and much more) is in 
> > the attached org-babel-detangle.org file.  The other org file contains some 
> > basic tests for demonstration.
> 
> I have looked into your write-up. Thanks for thoughtfully documenting
> everything!
> 
> That's a lot of changes, so I suggest splitting things into smaller
> pieces.
> 
> You mention that there are a couple of bugs in the existing code:
> 1. Incorrect interposition of Noweb prefix when =:comments noweb=
> 2. Vanishing empty lines
> Could you fix those bugs separately? We can do this first, before
> working on more significant changes.
> 
> Also, the example you provide about noweb prefix, might be problematic.
> In the example "hello" is not preceded by the prefix, which may break
> the tangling for indentation-sensitive languages like python.
> 
> #+begin_src emacs-lisp :tangle case-analysis.el :noweb yes :comments noweb 
> :noweb-prefix no
> before
> prefix <<a string>> in between <<a string>> suffix
> after
> #+end_src
> 
> tangles to
> 
> #+begin_src emacs-lisp
> ;; [[file:org-babel-detangle.org::*Two references in a row][Two references in 
> a row:1]]
> before
> prefix ;; [[file:org-babel-detangle.org::*Two references in a row][a string]]
> "hello"
> 
> -- 
> Ihor Radchenko // yantar92,
> Org mode maintainer,
> Learn more about Org mode at <https://orgmode.org/>.
> Support Org development at <https://liberapay.com/org-mode>,
> or support my work at <https://liberapay.com/yantar92>
> 

Reply via email to