emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dale <dale@codefu.org>
To: emacs-orgmode@gnu.org
Subject: Bug: clocktable doesn't preserve formulas with :scope file-with-archives
Date: Fri, 21 Oct 2016 13:13:57 -0500	[thread overview]
Message-ID: <CAEj9N4JSvxyXWxaJAEkKe6=L70GrcWhsiOyS07CR-bs3BoGoVQ@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2050 bytes --]

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

[-- Attachment #2: clocktable-formulas.patch --]
[-- Type: application/octet-stream, Size: 2139 bytes --]

 lisp/org-clock.el | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 3448d84..de7fcab 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2619,6 +2619,24 @@ from the dynamic block definition."
     ;; When exporting subtrees or regions the region might be
     ;; activated, so let's disable ̀delete-active-region'
     (let ((delete-active-region nil)) (backward-delete-char 1))
+    ;; Back to beginning, align the table, recalculate if necessary
+    (goto-char ipos)
+    (skip-chars-forward "^|")
+    (org-table-align)
+    (when org-hide-emphasis-markers
+      ;; we need to align a second time
+      (org-table-align))
+    (when sort
+      (save-excursion
+	(org-table-goto-line 3)
+	(org-table-goto-column (car sort))
+	(org-table-sort-lines nil (cdr sort))))
+    (when rm-file-column
+      ;; The file column is actually not wanted
+      (forward-char 1)
+      (org-table-delete-column))
+    (goto-char (org-table-end))
+    (backward-char 1)
     (if (setq formula (plist-get params :formula))
 	(cond
 	 ((eq formula '%)
@@ -2654,18 +2672,6 @@ from the dynamic block definition."
 	  (setq recalc t)
 	  (insert "\n" (match-string 1 (plist-get params :content)))
 	  (beginning-of-line 0))))
-    ;; Back to beginning, align the table, recalculate if necessary
-    (goto-char ipos)
-    (skip-chars-forward "^|")
-    (org-table-align)
-    (when org-hide-emphasis-markers
-      ;; we need to align a second time
-      (org-table-align))
-    (when sort
-      (save-excursion
-	(org-table-goto-line 3)
-	(org-table-goto-column (car sort))
-	(org-table-sort-lines nil (cdr sort))))
     (when recalc
       (if (eq formula '%)
 	  (save-excursion
@@ -2673,10 +2679,6 @@ from the dynamic block definition."
 	    (org-table-goto-column pcol nil 'force)
 	    (insert "%")))
       (org-table-recalculate 'all))
-    (when rm-file-column
-      ;; The file column is actually not wanted
-      (forward-char 1)
-      (org-table-delete-column))
     total-time))
 
 (defun org-clocktable-indent-string (level)

             reply	other threads:[~2016-10-21 18:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-21 18:13 Dale [this message]
2016-10-27  9:47 ` Bug: clocktable doesn't preserve formulas with :scope file-with-archives Nicolas Goaziou

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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='CAEj9N4JSvxyXWxaJAEkKe6=L70GrcWhsiOyS07CR-bs3BoGoVQ@mail.gmail.com' \
    --to=dale@codefu.org \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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