emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Mike McLean <mike.mclean@pobox.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Org Clock Table / Subtree Export subtle bug
Date: Fri, 27 Apr 2012 14:35:53 -0400	[thread overview]
Message-ID: <CANid5Q7YO2jWzLjbsXkhw-vZSs_ATQrrqtx7AexR985p6SWEtg@mail.gmail.com> (raw)

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


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

(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 (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 |
** 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

             reply	other threads:[~2012-04-27 18:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-27 18:35 Mike McLean [this message]
2012-04-28 23:19 ` Org Clock Table / Subtree Export subtle bug Bastien
2012-04-29 11:49   ` Mike McLean
2012-04-29 12:25     ` Mike McLean

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANid5Q7YO2jWzLjbsXkhw-vZSs_ATQrrqtx7AexR985p6SWEtg@mail.gmail.com \
    --to=mike.mclean@pobox.com \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


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