emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 0083123 2/2: Fix relocation with named cell referre


From: Vincent Belaïche
Subject: [Emacs-diffs] master 0083123 2/2: Fix relocation with named cell referred to by a one-symbol formula.
Date: Mon, 17 Jul 2017 14:54:47 -0400 (EDT)

branch: master
commit 0083123499cc29e301c197218d3809b225675e57
Author: Vincent Belaïche <address@hidden>
Commit: Vincent Belaïche <address@hidden>

    Fix relocation with named cell referred to by a one-symbol formula.
    
    * lisp/ses.el (ses-replace-name-in-formula): Fix bug for it to
    work also with one symbol formulas.
    
    * test/lisp/ses-tests.el
    (ses-tests-renaming-cell-with-one-symbol-formula): Add new
    test for renaming with relocating a one symbol formula.
---
 lisp/ses.el            | 12 ++++++++----
 test/lisp/ses-tests.el | 22 ++++++++++++++++++++++
 2 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/lisp/ses.el b/lisp/ses.el
index 2e21434..ed5e166 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -3634,8 +3634,12 @@ highlighted range in the spreadsheet."
 
 (defun ses-replace-name-in-formula (formula old-name new-name)
   (let ((new-formula formula))
-    (unless (and (consp formula)
-                (eq (car-safe formula) 'quote))
+    (cond
+     ((eq (car-safe formula) 'quote))
+     ((symbolp formula)
+      (if (eq formula old-name)
+          (setq new-formula new-name)))
+     ((consp formula)
       (while formula
        (let ((elt (car-safe formula)))
          (cond
@@ -3644,8 +3648,8 @@ highlighted range in the spreadsheet."
           ((and (symbolp elt)
                 (eq (car-safe formula) old-name))
            (setcar formula new-name))))
-       (setq formula (cdr formula))))
-    new-formula))
+       (setq formula (cdr formula)))))
+  new-formula))
 
 (defun ses-rename-cell (new-name &optional cell)
   "Rename current cell."
diff --git a/test/lisp/ses-tests.el b/test/lisp/ses-tests.el
index 196f710..add94ae 100644
--- a/test/lisp/ses-tests.el
+++ b/test/lisp/ses-tests.el
@@ -106,6 +106,28 @@ renaming A1 to `foo' makes `foo' value equal to 2."
       (should (equal (ses-cell-formula 1 0) '(1+ foo)))
       (should (eq A2 2)))))
 
+(ert-deftest ses-tests-renaming-cell-with-one-symbol-formula ()
+  "Check that setting A1 to 1 and A2 to A1, and then renaming A1
+to `foo' makes `foo' value equal to 1. Then set A1 to 2 and check
+that `foo' becomes 2."
+  (let ((ses-initial-size '(3 . 1)))
+    (with-temp-buffer
+      (ses-mode)
+      (dolist (c '((0 0 1) (1 0 A1)))
+        (apply 'funcall-interactively 'ses-edit-cell c))
+      (ses-command-hook); deferred recalc
+      (ses-rename-cell 'foo (ses-get-cell 0 0))
+      (ses-command-hook); deferred recalc
+      (should-not  (local-variable-p 'A1))
+      (should (eq foo 1))
+      (should (equal (ses-cell-formula 1 0) 'foo))
+      (should (eq A2 1))
+      (funcall-interactively 'ses-edit-cell 0 0 2)
+      (ses-command-hook); deferred recalc
+      (should (eq A2 2))
+      (should (eq foo 2)))))
+
+
 ;; ROW INSERTION TESTS
 ;; ======================================================================
 



reply via email to

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