Org-Babel Tangles Out of Order

Site Nav

I'm currently suffering from an issue where running org-babel-tangle results in blocks being tangled such that they end up out of order in the destination file. Specifically when updating previously tangled files the newly added blocks are appended to the output file such that the product reflects the order in which the blocks were added rather than the order in which they are defined. This suggests some cache or similar lingering state which is effectively providing parameters to the tangling beyond that which is contianed within the source file, thereby tampering with the produced output.

This may be standard, documented behavior but currently I'm just going to try to diagnose it from the inside out as a chance to get more familiar with the babel internals.

I'm currently calling org-babel-tangle where the relevant ordering logic involves a call to mapc which applies some of the actual tangling logic across the blocks retreived by org-babel-tangle-collect-blocks. The structure of this code leaves me wishing some kind of piping or threading macro were used.

org-babel-tangle-collect-blocks in turn calls org-babel-map-src-blocks but also does some reordering of the blocks. It looks as though it collects the blocks from the end of the buffer backward and then reverses them before passing them through. This certainly feels like a place where it is worth trying to experiment with the code a bit.

But…the problem has stopped for now and so too will my investigation.

Author: mwhipple

Created: 2020-10-27 Tue 19:36