Konstantin Borisov <ir...@ya.ru> writes: > Currently there is a possibility to use =:comments noweb= header option > in src block, that adds comments with links to source block to the > tangled files. And this option works great with ~org-babel-detangle~ in > simple cases, but it fails to work in more complex ones. > ...
This is a known problem. See https://list.orgmode.org/orgmode/1513516023.10763084.1682269758...@mail.yahoo.com/ > I also propose to not use links for blocks reference, but line-numbers > of where block starts in org-file. As far as it's not possible to fill > the same tangled file from different org-files, I propose to make > special comment line with the file where it was tangled from. Thus > comments will be shorter and easier to view (org-links not working in > source files anyway). Using line numbers is not exactly reliable. What if the source org file changes? The line numbers will not be correct then. > ... > In comments it have following information: > - where to find the org-file this file was tangled from (=ORG-FILE > filepath=) > - where to find source block with sources (=SRC line-in-org-file= and > =SRC line-in-org-file ends here=) > - the borders of noweb references (=NOWEB noweb-ref= and =NOWEB > noweb-ref ends here=) > ... > To acheive such result we need to modify the > ~org-babel-expand-noweb-reference~ function to not just insert the > source blocks links, but also adding the noweb reference begin/end > comments lines to tangled file. > > Detangle function ~org-babel-detangle~ with such structure of comments > will have enough information to properly detangle source blocks using > the following algorithm: > > 1. Load tangled file content to temporary buffer > 2. Find first source block that do not have any comment lines started > with =SRC= and =NOWEB= (the leaves of noweb source blocks tree) inside. > 3. If found > 3.1. detangle that source block and remove it from processing buffer > 3.2. go to step 2. > 4. If not found > 4.1. find the pair of comments started with =NOWEB= and apropriate > noweb reference > 4.2. If found > 4.2.1. it should be empty between those comments > 4.2.2. replace those comments lines with the apropriate noweb > reference code > 4.2.3. go to step 2. > 4.3. If not found > 4.3.1. Complete > ... I believe that the ultimate solution will be using https://leo-editor.github.io/leo-editor/appendices.html#the-mulder-ream-update-algorithm -- 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>