Hi Eric and Samuel, As I understand it, the problem is that the undo history gets scrambled by the interleaving of user edits (in the indirect source-editing buffer) and automatic changes introduced by org (un- and re-indenting the source code). I have the following patch, which seems to prevent the misbehavior Samuel noticed. It has the drawback of not keeping the fine-grained undo information: after org-src-edit-exit, all changes made during the edit are seen as only one change, and undone as a unit. I think the problem of interleaving the automatic and user-driven changes in a sensible way is tricky. We don’t want the first invocation of undo after org-src-edit-exit to remove the contents of the code block, which is what a naive approach gives (since org-src-edit-exit deletes then reinserts the code block contents). I’ve been running with this patch for a while and not noticed any ill effects. But I haven’t made a concerted attempt to test undo around code blocks, which is why I’ve held off on pushing it. If it fixes Samuel’s problem and looks good, perhaps it is ready to go.