Rudolf Adamkovič writes: >>> (1) re-opening the file after export always re-opens it, and >> >> I am not sure how to test this part. > > How about the attached patch? > > It mirrors the manual steps (find-file, export, kill-buffer, find-file), > except it calls just the 'org-export-copy-buffer' procedure instead of > exporting to HTML. The test fails without your fix and passes with it. The test in the patch is erroneous. `org-export-copy-buffer', unless it kills the generated buffer, does nothing about `buffer-file-name' local variable. The patch is only working by accident because `find-file' opens the first buffer with matching `buffer-file-name'. If there are multiple such buffers, the return value depends on their order. I have updated `org-export-with-buffer-copy' macro to take care about this `buffer-file-name' issue uniformly without a need to put workarounds into every caller. I have also updated your patch using a more appropriate testing assertions. It now uses the updated macro. See the attached patches. (I'd like this patches to be tested on real export first as it is touching on very basic export routines).