emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 825b896acfe 3/3: Fix 13 years old bug#5852 !


From: Vincent Belaïche
Subject: master 825b896acfe 3/3: Fix 13 years old bug#5852 !
Date: Fri, 29 Dec 2023 06:42:05 -0500 (EST)

branch: master
commit 825b896acfe2b2d2b3a8f29b4ed1d5810d222663
Author: Vincent Belaïche <vincentb1@users.sourceforge.net>
Commit: Vincent Belaïche <vincentb1@users.sourceforge.net>

    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.
---
 lisp/ses.el            | 29 ++++++++++++++++-------------
 test/lisp/ses-tests.el | 10 +++-------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/lisp/ses.el b/lisp/ses.el
index 02ed2faae3c..b5193c3e4b8 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -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)
diff --git a/test/lisp/ses-tests.el b/test/lisp/ses-tests.el
index 9983ec0d09f..e2ff41c5875 100644
--- a/test/lisp/ses-tests.el
+++ b/test/lisp/ses-tests.el
@@ -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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]