Re: [O] Bug: clocktable doesn't preserve formulas with :scope file-with-archives

2016-10-27 Thread Nicolas Goaziou
Hello,

Dale  writes:

> Hi!  I've found that the "#+TBLFM:" in a clocktable can get changed or
> deleted when used together with ":scope file-with-archives".  Here's a
> minimal org file to reproduce with:
>
> --8<--
> * Test
> :LOGBOOK:
> CLOCK: [2016-10-20 Thu 17:42]--[2016-10-20 Thu 18:03] =>  0:21
> :END:
>
> #+BEGIN: clocktable :scope file-with-archives
> #+TBLFM: $3=string("foo")
>
> #+END:
> --8<--
>
> Steps to reproduce:
>
> 1. emacs -Q, load above file with org-mode from Git
>
> 2. Update clocktable dblock (move to "#+BEGIN" and C-c C-c)
>
> Expected result: a third column is added with value "foo" in every
> row; #+TBLFM line is preserved
>
> Observed result: table has two columns, the second of which contains
> "foo" in every row; #+TBLFM line changes from $3=string("foo") to
> $2=string("foo")
>
> If you keep updating the block, the formula's "$2" then becomes "$1".
> Do it one more time and the "#+TBLFM:" is preserved but now the
> formula is gone entirely.
>
> Emacs  : GNU Emacs 25.1.1 (x86_64-apple-darwin15.6.0)
>  of 2016-09-23
> Package: Org-mode version 8.2.10 (release_8.2.10 @ 
> /opt/local/share/emacs/25.1/\
> lisp/org/)
>
> I have also reproduced this with org-mode from Git as of an hour or so ago.
>
> My hunch is that the problem is in org-clocktable-write-default.  It
> writes the table (the dblock's contents have already been deleted),
> restores any #+TBLFM: line that used to be there pre-update, and then,
> if you're using :scope file-with-archives, it deletes the file column,
> which is the first column.  The order here is the problem:
> org-table-delete-column updates the formula in #+TBLFM, decrementing
> the column reference to account for the deleted column.
>
> If this sounds right then I'd suggest that the solution may be as
> simple as just updating org-clocktable-write-default to insert table
> formulas *after* deleting the file column

Thank you for the report and the analysis. This is now fixed.

Regards,

-- 
Nicolas Goaziou



[O] Bug: clocktable doesn't preserve formulas with :scope file-with-archives

2016-10-21 Thread Dale
Hi!  I've found that the "#+TBLFM:" in a clocktable can get changed or
deleted when used together with ":scope file-with-archives".  Here's a
minimal org file to reproduce with:

--8<--
* Test
:LOGBOOK:
CLOCK: [2016-10-20 Thu 17:42]--[2016-10-20 Thu 18:03] =>  0:21
:END:

#+BEGIN: clocktable :scope file-with-archives
#+TBLFM: $3=string("foo")
#+END:
--8<--

Steps to reproduce:

1. emacs -Q, load above file with org-mode from Git

2. Update clocktable dblock (move to "#+BEGIN" and C-c C-c)

Expected result: a third column is added with value "foo" in every
row; #+TBLFM line is preserved

Observed result: table has two columns, the second of which contains
"foo" in every row; #+TBLFM line changes from $3=string("foo") to
$2=string("foo")

If you keep updating the block, the formula's "$2" then becomes "$1".
Do it one more time and the "#+TBLFM:" is preserved but now the
formula is gone entirely.

Emacs  : GNU Emacs 25.1.1 (x86_64-apple-darwin15.6.0)
 of 2016-09-23
Package: Org-mode version 8.2.10 (release_8.2.10 @ /opt/local/share/emacs/25.1/\
lisp/org/)

I have also reproduced this with org-mode from Git as of an hour or so ago.

My hunch is that the problem is in org-clocktable-write-default.  It
writes the table (the dblock's contents have already been deleted),
restores any #+TBLFM: line that used to be there pre-update, and then,
if you're using :scope file-with-archives, it deletes the file column,
which is the first column.  The order here is the problem:
org-table-delete-column updates the formula in #+TBLFM, decrementing
the column reference to account for the deleted column.

If this sounds right then I'd suggest that the solution may be as
simple as just updating org-clocktable-write-default to insert table
formulas *after* deleting the file column, along with some

I'm attaching a patch but I'm not sure whether you'll be able to use
it because my FSF assignment hasn't been updated for my new employer.
Even if you can't use it, hopefully my description above is still
useful.

Thanks!

Dale


clocktable-formulas.patch
Description: Binary data