emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Org Clock Table / Subtree Export subtle bug
@ 2012-04-27 18:35 Mike McLean
  2012-04-28 23:19 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Mike McLean @ 2012-04-27 18:35 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 3808 bytes --]

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)

[-- Attachment #1.2: Type: text/html, Size: 17510 bytes --]

[-- Attachment #2: test.org --]
[-- Type: application/octet-stream, Size: 515 bytes --]

* Project A
#+BEGIN: clocktable :maxlevel 2 :scope subtree
Clock summary at [2012-04-27 Fri 13:02]

| 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Org Clock Table / Subtree Export subtle bug
  2012-04-27 18:35 Org Clock Table / Subtree Export subtle bug Mike McLean
@ 2012-04-28 23:19 ` Bastien
  2012-04-29 11:49   ` Mike McLean
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2012-04-28 23:19 UTC (permalink / raw)
  To: Mike McLean; +Cc: emacs-orgmode

Hi Mike,

thanks very much for the detailed bug report.

Mike McLean <mike.mclean@pobox.com> writes:

> 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.

The trick is to use (let ((delete-active-region nil)) ...) so that 
the active region is not deleted by such adjustments.

I pushed a fix.

Thanks!

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Org Clock Table / Subtree Export subtle bug
  2012-04-28 23:19 ` Bastien
@ 2012-04-29 11:49   ` Mike McLean
  2012-04-29 12:25     ` Mike McLean
  0 siblings, 1 reply; 4+ messages in thread
From: Mike McLean @ 2012-04-29 11:49 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode


On Apr 28, 2012, at 7:19 PM, Bastien wrote:

> Hi Mike,
> 
> thanks very much for the detailed bug report.
> 
> Mike McLean <mike.mclean@pobox.com> writes:
> 
>> 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.
> 
> The trick is to use (let ((delete-active-region nil)) ...) so that 
> the active region is not deleted by such adjustments.

Interesting, I was going to play a bit today and try things like (save-excursion (deactivate-mark) … ) but didn't know if that was the right approach or not. The delete-active-region sure seems simpler :)

> I pushed a fix.

Thank you

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Org Clock Table / Subtree Export subtle bug
  2012-04-29 11:49   ` Mike McLean
@ 2012-04-29 12:25     ` Mike McLean
  0 siblings, 0 replies; 4+ messages in thread
From: Mike McLean @ 2012-04-29 12:25 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

On Apr 29, 2012, at 7:49 AM, Mike McLean wrote:

> 
> On Apr 28, 2012, at 7:19 PM, Bastien wrote:
> 
>> The trick is to use (let ((delete-active-region nil)) ...) so that 
>> the active region is not deleted by such adjustments.
> 
> Interesting, I was going to play a bit today and try things like (save-excursion (deactivate-mark) … ) but didn't know if that was the right approach or not. The delete-active-region sure seems simpler :)
> 
>> I pushed a fix.
> 
> Thank you

I can confirm that the single-tree-export no longer corrupts the Org file and works with the EMF file.

Strange though that now in my full setup the generated export does not include the Clock Report table. (This works fine with the test file in ~emacs -q~ so this is my issue).

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-29 12:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-27 18:35 Org Clock Table / Subtree Export subtle bug Mike McLean
2012-04-28 23:19 ` Bastien
2012-04-29 11:49   ` Mike McLean
2012-04-29 12:25     ` Mike McLean

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).