emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Table refuses to forget cell formula which once overrode a column formula
@ 2017-11-14 11:27 Ruy Exel
  2017-11-15 16:42 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Ruy Exel @ 2017-11-14 11:27 UTC (permalink / raw)
  To: emacs-orgmode

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

This bug report is motivated by a question I asked at


https://emacs.stackexchange.com/questions/36855/table-refuses-to-forget-cell-formula-which-once-overrode-a-column-formula

and all of the necessary information can probably be obtained from there.
Nevertheless let me repeat it here:

---------------------------------------------------------

The following is very simple org-mode spreadsheet in which the cells in the
second column show the triple of the corresponding cell in the first column
due to the "column formula" in its TBLFM row $2=3*$1;N. However the third
row (actually row @4) is an exception because of the "cell formula"
@4$2=string("Exception") which expectedly overrides the above column
formula.

|--------+-----------|
| Number |    Triple |
|--------+-----------|
|      1 |         3 |
|      2 |         6 |
|      3 | Exception |
|      4 |        12 |
|--------+-----------|
#+TBLFM: $2=3*$1::@4$2=string("Exception")

So all is well. Below you will find a copy of the above table, except that,
after copying, I have deleted the exceptional formula affecting cell @4$2.

|--------+-----------|
| Number |    Triple |
|--------+-----------|
|      1 |         3 |
|      2 |         6 |
|      3 | Exception |
|      4 |        12 |
|--------+-----------|
#+TBLFM: $2=3*$1

One would expect that, after updating this table with C-u C-c *, or C-c C-c
in the TBLFM line, the exceptional value in cell @4$2 would revert to the
triple of '3', but instead the string "Exception" stays put. Is this a bug
or am I doing something wrong?

I noticed that if I save the file, close it (kill-buffer) and then reopen
it, the strange behaviour disapears, namely, updating the table with C-u
C-c * causes cell @4$2 to turn to '9', as expected.

I am using GNU Emacs 24.3.1 and the latest version of org-mode.

---------------------------------------------------------

The answer I got from emacs.stackexchange.com says:

---------------------------------------------------------

The persistence of the string exception has nothing to do with copying. If
you recalculate the original table and afterwards remove the field formula
from it you also have the problem that exception is not replaced by 9 at
the next recalculation.

The reason for that behavior is that the text property :org-untouchable is
put on the output of field formulas. The normal function of
:org-untouchable is to prevent the modification of cells with field
formulas during the evaluation of a column formulas.

In my opinion the :org-untouchable property should be removed at the
beginning of calls to org-table-iterate and at the beginning of interactive
calls of org-table-recalculate.

You can obtain this behavior with the advices below. These advices are
tested with org-version 9.0.5 in emacs 25.1.50.2.

I would agree that the original behavior is faulty. Therefore, I suggest to
file a bug-report at https://lists.gnu.org/mailman/listinfo/emacs-orgmode.
A proper bug-fix should probably be implemented differently.

(defun org-table-remove-untouchable (&rest _args)
  "Remove `:org-untouchable' property from org-table."
  (save-excursion
    (cl-assert (org-at-table-p) nil "Not in org-table.")
    (remove-text-properties (org-table-begin) (org-table-end)
'(:org-untouchable nil))))

(defun org-table-recalculate-remove-untouchable (&optional all _noalign)
  "Remove `:org-untouchable' property at the beginning of
`org-table-iterate'.
Use this function as :before advice of `org-table-iterate'."
  (when (and (called-interactively-p 'any)
         all)
    (org-table-remove-untouchable)))

(advice-add 'org-table-iterate :before #'org-table-remove-untouchable)
(advice-add 'org-table-recalculate :before
#'org-table-recalculate-remove-untouchable)

---------------------------------------------------------

Sincerely,
Ruy Exel

[-- Attachment #2: Type: text/html, Size: 4740 bytes --]

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

end of thread, other threads:[~2017-11-15 23:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-14 11:27 Table refuses to forget cell formula which once overrode a column formula Ruy Exel
2017-11-15 16:42 ` Nicolas Goaziou
     [not found]   ` <CAB8Wf+-VxdCKMfqZjRfYvMdQPwwzgs=FtWESpYuhokK3sZe8sw@mail.gmail.com>
2017-11-15 19:17     ` Ruy Exel
2017-11-15 21:07       ` Nick Dokos
2017-11-15 21:54       ` Nicolas Goaziou
2017-11-15 23:30         ` Ruy Exel

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