Hello I have found a bug with clock tables and even have localized the exact point in org-clock.el where it occurs. I don’t know enough of the Org Mode code base to figure out the best solution and submit a patch. The general symptom is that if: - You have org-update-all-dblocks added to org-export-first-hook with the goal of ensuring that dynamic blocks are current before every export; AND - You are exporting only a region of the file, for example using C-c C-e 1 b (buffer/subtree export) The Mark terminating the end of the region to be exported is carried into the org-clocktable-write-default formatting function and the call of (backward-delete-char 1) on line 2352 oforg-clock.el deletes a region (between the Mark of the initial call and point, which is immediately before the #+END: construct of the clock table). Deletion of the #+END: construct malforms the clock table and ultimately the export fails leaving the Org file is a corrupt state. 1 Detailed steps to reproduce 1.1 Emacs Initialization Launch Emacs clean: /Applications/Emacs.app/Contents/MacOS/Emacs -Q Add the update to org-export-first-hook by evaluating the follwing line in *scratch* (add-hook 'org-export-first-hook 'org-update-all-dblocks) Report versions (note this report is done from the non-Git-HEAD Org 7.8.09 included with Emacs, but the problem also exists in HEAD): M-x emacs-version GNU Emacs 24.1.50.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2012-04-27 on bob.porkrind.org M-x org-version Org-mode version 7.8.09 1.2 Baseline and Error Tests 1.2.1 Test File Open the following test file * Project A#+BEGIN: clocktable :maxlevel 2 :scope subtree Clock summary at [2012-04-27 Fri 14:30] | Headline | Time | ||--------------+--------+------|| *Total time* | *2:59* | ||--------------+--------+------|| Project A | 2:59 | || Task A1 | | 2:00 || Task A2 | | 0:59 | #+END:** Task A1 CLOCK: [2012-04-26 Fri 11:58]--[2012-04-26 Thu 13:58] => 2:00** Task A2 CLOCK: [2012-04-27 Fri 09:00]--[2012-04-27 Fri 09:59] => 0:59* Project B** Task B1 1.2.2 Baseline test Export the entire buffer as a baseline test C-c C-e b The result is as expected: - A valid HTML export - The Clock Summary line changes to reflect the current time (showing that org-update-all-dblocks) ran correctly 1.2.3 Reproduce the Error Put the cursor on the Project A line and attempt to export just the Project A subtree C-c C-e 1 b The expected result is a (smaller than before) valid HTML export. The actual result is: - org-map-dblocks: Dynamic block not terminated in the echo area - Lines between #+END: and Project B are deleted from the file resulting in the following invalid Org file #+STARTUP: showeverything * Project A #+BEGIN: clocktable :maxlevel 2 :scope subtree Clock summary at [2012-04-27 Fri 14:15] | Headline | Time | | |--------------+--------+------| | *Total time* | *2:59* | | |--------------+--------+------| | Project A | 2:59 | | | Task A1 | | 2:00 | | Task A2 | | 0:59 | * Project B 1.3 Diagnosis Tracing through org-clock.el I found the culprit on line 2352, if I add a (debug) statement immediately before that line I see the following: - on a normal clock table update (C-c C-c on the #+BEGIN: line) the debugger enters and there is no region highlighted - when trying the subtree export the debuggers enters and there is a highlighted active region in test.org from the end of the table (Point) to the end of the entire Project Asubtree (Mark, from the selection made by the export subtree code)