Ihor Radchenko <yanta...@posteo.net> writes: > Do I understand correctly that your package is adding the following new > features: > > 1. Automatically manages balanced > `org-babel-tangle'/`org-babel-detangle' in Org sources and target > buffers. > 2. Attempts to make more fine-grained tangling/detanging functionality > by controlling tangling behaviour on per-src-block basis (via > :tangle-sync skip/pull/export/both) >
That is correct > If so, I think that (2) probably belongs to the main babel code > (`org-babel-tangle' and `org-babel-detangle'). Since you are > contributing to Org directly, you are free to modify these functions as > you need. > > Note that your current approach with `org-babel-tangle-sync-synchronize' > will give unexpected results when one edits multiple src blocks or the > corresponding tangled source in multiple places - the :tangle-sync value > is only checked at point and `org-babel-tangle'/`org-babel-detange' is > then called for the whole buffer, not just for the current code block. That's... a really good point. I didn't consider that I'm calling a tangle or detangle function on an entire file based on the =:tangle-sync action= of a single block... which might have different actions in another block for the same file! I've attached a toy.org file which should explain what the desired action would be in such a situation, and I fully agree that I will likely need to modify the current tangle and detangle code so that the sync direction is on a per-block basis, and not per-file. I will work on this a bit more and submit a full patch with this in mind. Best, Mehmet
#+TITLE: Sync Many Blocks #+PROPERTY: header-args :tangle /tmp/default_tangle.txt :comments yes * Default Tangle The =:tangle= target here is given by the ~PROPERTY~ header. It is made up of three parts which synchronize with the tangled destination file in 3 different ways as given below: ** File Contents *** Free Head #+begin_src conf This is some text that can be synced both ways #+end_src *** Pull Middle #+begin_src conf :tangle-sync import The middle text only retrieves from the default tangle file #+end_src *** Push tail #+begin_src conf :tangle-sync export This last piece of text only exports from the source org mode file. #+end_src * Desired Function When =org-babel-tangle= is called, only the [[Free Head]] and [[Push tail]] sections are tangled. The middle section in the tangled file is _skipped_. When =org-babel-detangle= is called, only the [[Pull Middle]] section is updated here. The other two sections are _skipped_. * Why skipped? The functions suffixes explicitly state a direction (=tangle= / =detangle=), and it's probably important that we retain this directionality. If we want to synchronize all blocks (i.e. import the middle section from the tangled file during =org-babel-tangle=, and export the head and tail sections during =org-babel-detangle=), then perhaps we set a specific custom variable =(setq org-babel-tangle-alwayssync t)=? Or, we create a specific function =org-babel-sync= (for lack of better name) which tangles/detangles in whatever desired direction the source block specifies.