Commit 825b896a authored by Vincent Belaïche's avatar Vincent Belaïche
Browse files

Fix 13 years old bug#5852 !

Sometimes recalculating a cell does not change its value, however it
still have to be written to the data area when the reference list is
changed

* lisp/ses.el (ses-cell-set-formula): Fix bug#5852, at last !

* test/lisp/ses-tests.el
(ses-set-formula-write-cells-with-changed-references): Rename test
from ses-bug5852, do not expect failure, and update description.
parent b96087d4
Pipeline #27663 failed with stages
in 8 minutes and 25 seconds
......@@ -884,7 +884,7 @@ means Emacs will crash if FORMULA contains a circular list."
(newref (ses-formula-references formula))
(inhibit-quit t)
not-a-cell-ref-list
x xrow xcol)
x xref xrow xcol)
(cl-pushnew sym ses--deferred-recalc)
;;Delete old references from this cell. Skip the ones that are also
;;in the new list.
......@@ -893,24 +893,27 @@ means Emacs will crash if FORMULA contains a circular list."
;; because we do not cancel edit when the user provides a
;; false reference in it, then we need to check that ref
;; points to a cell that is within the spreadsheet.
(setq x (ses-sym-rowcol ref))
(and x
(< (setq xrow (car x)) ses--numrows)
(< (setq xcol (cdr x)) ses--numcols)
(ses-set-cell xrow xcol 'references
(delq sym (ses-cell-references xrow xcol))))))
(when
(and (setq x (ses-sym-rowcol ref))
(< (setq xrow (car x)) ses--numrows)
(< (setq xcol (cdr x)) ses--numcols))
;; cell ref has to be re-written to data area as its
;; reference list is changed
(cl-pushnew x ses--deferred-write :test #'equal)
(ses-set-cell xrow xcol 'references
(delq sym (ses-cell-references xrow xcol))))))
;;Add new ones. Skip ones left over from old list
(dolist (ref newref)
(setq x (ses-sym-rowcol ref))
;;Do not trust the user, the reference may be outside the spreadsheet
(if (and
x
(setq x (ses-sym-rowcol ref))
(< (setq xrow (car x)) ses--numrows)
(< (setq xcol (cdr x)) ses--numcols))
(progn
(setq x (ses-cell-references xrow xcol))
(or (memq sym x)
(ses-set-cell xrow xcol 'references (cons sym x))))
(unless (memq sym (setq xref (ses-cell-references xrow xcol)))
;; cell ref has to be re-written to data area as its
;; reference list is changed
(cl-pushnew x ses--deferred-write :test #'equal)
(ses-set-cell xrow xcol 'references (cons sym xref)))
(cl-pushnew ref not-a-cell-ref-list)))
(ses-formula-record formula)
(ses-set-cell row col 'formula formula)
......
......@@ -241,13 +241,9 @@ to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
(ses-command-hook)
(should (eq (ses--cell-at-pos (point)) 'ses--toto)))))
(ert-deftest ses-bug5852 ()
"This this bug is not yet fixed, the test is expected to fail.
The bug is that after modifying formula of B4 reference list of
cell B2 is correct in the memory data structure, but not in the
written ses-cell macros in the data area, this is why the second
`should' statement fails after reloading the sheet."
:expected-result :failed
(ert-deftest ses-set-formula-write-cells-with-changed-references ()
"Fix of bug#5852. When setting a formula has some cell with
changed references, this cell has to be rewritten to data area."
(let ((ses-initial-size '(4 . 3))
ses-after-entry-functions beg)
(with-temp-buffer
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment