From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mike McLean Subject: Org Clock Table / Subtree Export subtle bug Date: Fri, 27 Apr 2012 14:35:53 -0400 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=e89a8f22bd8908c14a04bead6151 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:46212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNq25-00089l-Vm for emacs-orgmode@gnu.org; Fri, 27 Apr 2012 14:36:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SNq23-0007Bh-97 for emacs-orgmode@gnu.org; Fri, 27 Apr 2012 14:36:41 -0400 Received: from a-pb-sasl-sd.pobox.com ([74.115.168.62]:58955 helo=sasl.smtp.pobox.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SNq22-00075M-VO for emacs-orgmode@gnu.org; Fri, 27 Apr 2012 14:36:39 -0400 Received: from sasl.smtp.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 78682A720 for ; Fri, 27 Apr 2012 14:36:15 -0400 (EDT) Received: from a-pb-sasl-sd.pobox.com (unknown [127.0.0.1]) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTP id 71792A71F for ; Fri, 27 Apr 2012 14:36:15 -0400 (EDT) Received: from mail-lb0-f169.google.com (unknown [209.85.217.169]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by a-pb-sasl-sd.pobox.com (Postfix) with ESMTPSA id 8D194A71D for ; Fri, 27 Apr 2012 14:36:14 -0400 (EDT) Received: by lbjn8 with SMTP id n8so391173lbj.0 for ; Fri, 27 Apr 2012 11:36:13 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode --e89a8f22bd8908c14a04bead6151 Content-Type: multipart/alternative; boundary=e89a8f22bd8908c14604bead614f --e89a8f22bd8908c14604bead614f Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable 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=92t know enough of the Org Mod= e 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] =3D> 2:00** Task = A2 CLOCK: [2012-04-27 Fri 09:00]--[2012-04-27 Fri 09:59] =3D> 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) --e89a8f22bd8908c14604bead614f Content-Type: text/html; charset=windows-1252 Content-Transfer-Encoding: quoted-printable

Hello

I have found a bug with clock tables and even have localized the exact poin= t in=A0org-clo= ck.el=A0where it occurs. I don=92t 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=A0org-update-all-dblocks=A0added to=A0org-export-first-hook=A0with 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=A0C-c C-e 1 b= =A0(buffer/subtree export)

The Mark terminating the end of the region to be exported is carried into t= he=A0org-clock= table-write-default=A0formatting function and the call of=A0(backward-delete-char = 1)=A0on line 2352 oforg-clock.el=A0deletes a region (between the Mark of th= e initial call and point, which is immediately before the=A0#+END:=A0construct of = the clock table). Deletion of the=A0#+END:=A0construct malforms the clock table an= d ultimately the export fails leaving the Org file is a corrupt state.

1=A0Detail= ed steps to reproduce

1.1=A0Emac= s Initialization

Launch Emacs clean:


/Applications/Emacs.app/Contents/MacOS/Emacs -Q

Add the update to=A0org-export-first-hook=A0by evaluating the follwing li= ne in=A0*scrat= ch*


(add-hook 'org-export-first-hook 'org-update-all-dblocks)

Report versions (note this report is done from the non-Git-HEAD Or= g 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=A0Base= line and Error Tests

1.2.1=A0Te= st 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-2=
6 Thu 13:58] =3D>  2:00
** Task A2
   CLOCK: [2012-04-27 Fri 09:00]--[2012-04-2=
7 Fri 09:59] =3D>  0:59
* Project B
** Task B1

1.2.2=A0Ba= seline test

Export the entire buffer as a baseline test


C-c C-e b

The result is as expected:

  • A valid HTML export
  • The=A0Clock S= ummary=A0line changes to reflect the current time (showing that=A0org-update-all-d= blocks) ran correctly

1.2.3=A0Re= produce 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.<= /p>

The actual result is:

  • org-map-dblocks: Dynamic block not terminated=A0in the echo area
  • Lines between=A0#+END:=A0and 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=A0Diag= nosis

Tracing through=A0org-clock.el=A0I found the culprit on line 2352, if = I add a=A0(deb= ug)=A0statement immediately before that line I see the following:

  • on a normal clock table update (C-c C-c=A0on the=A0#+BEGIN:=A0line) the debugger= enters and there is no region highlighted
  • when trying the subtree export the debuggers enters and there is a high= lighted active region in=A0test.org=A0from the end= of the table (Point) to the end of the entire=A0Project Asubtree (Mark, from the = selection made by the export subtree code)
--e89a8f22bd8908c14604bead614f-- --e89a8f22bd8908c14a04bead6151 Content-Type: application/octet-stream; name="test.org" Content-Disposition: attachment; filename="test.org" Content-Transfer-Encoding: base64 X-Attachment-Id: f_h1jl0nvf0 KiBQcm9qZWN0IEEKIytCRUdJTjogY2xvY2t0YWJsZSA6bWF4bGV2ZWwgMiA6c2NvcGUgc3VidHJl ZQpDbG9jayBzdW1tYXJ5IGF0IFsyMDEyLTA0LTI3IEZyaSAxMzowMl0KCnwgSGVhZGxpbmUgICAg IHwgVGltZSAgIHwgICAgICB8CnwtLS0tLS0tLS0tLS0tLSstLS0tLS0tLSstLS0tLS18CnwgKlRv dGFsIHRpbWUqIHwgKjI6NTkqIHwgICAgICB8CnwtLS0tLS0tLS0tLS0tLSstLS0tLS0tLSstLS0t LS18CnwgUHJvamVjdCBBICAgIHwgMjo1OSAgIHwgICAgICB8CnwgVGFzayBBMSAgICAgIHwgICAg ICAgIHwgMjowMCB8CnwgVGFzayBBMiAgICAgIHwgICAgICAgIHwgMDo1OSB8CiMrRU5EOgoqKiBU YXNrIEExCiAgIENMT0NLOiBbMjAxMi0wNC0yNiBGcmkgMTE6NThdLS1bMjAxMi0wNC0yNiBUaHUg MTM6NThdID0+ICAyOjAwCioqIFRhc2sgQTIKICAgQ0xPQ0s6IFsyMDEyLTA0LTI3IEZyaSAwOTow MF0tLVsyMDEyLTA0LTI3IEZyaSAwOTo1OV0gPT4gIDA6NTkKKiBQcm9qZWN0IEIKKiogVGFzayBC MQo= --e89a8f22bd8908c14a04bead6151--