aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ses.el46
1 files changed, 32 insertions, 14 deletions
diff --git a/lisp/ses.el b/lisp/ses.el
index b3686076358..97bade380ec 100644
--- a/lisp/ses.el
+++ b/lisp/ses.el
@@ -437,7 +437,7 @@ is nil if SYM is not a symbol that names a cell."
437 (declare (debug t)) 437 (declare (debug t))
438 `(let ((rc (and (symbolp ,sym) (get ,sym 'ses-cell)))) 438 `(let ((rc (and (symbolp ,sym) (get ,sym 'ses-cell))))
439 (if (eq rc :ses-named) 439 (if (eq rc :ses-named)
440 (gethash ,sym ses--named-cell-hashmap) 440 (and ses--named-cell-hashmap (gethash ,sym ses--named-cell-hashmap))
441 rc))) 441 rc)))
442 442
443(defun ses-cell-p (cell) 443(defun ses-cell-p (cell)
@@ -868,27 +868,39 @@ means Emacs will crash if FORMULA contains a circular list."
868 (oldref (ses-formula-references old)) 868 (oldref (ses-formula-references old))
869 (newref (ses-formula-references formula)) 869 (newref (ses-formula-references formula))
870 (inhibit-quit t) 870 (inhibit-quit t)
871 not-a-cell-ref-list
871 x xrow xcol) 872 x xrow xcol)
872 (cl-pushnew sym ses--deferred-recalc) 873 (cl-pushnew sym ses--deferred-recalc)
873 ;;Delete old references from this cell. Skip the ones that are also 874 ;;Delete old references from this cell. Skip the ones that are also
874 ;;in the new list. 875 ;;in the new list.
875 (dolist (ref oldref) 876 (dolist (ref oldref)
876 (unless (memq ref newref) 877 (unless (memq ref newref)
877 (setq x (ses-sym-rowcol ref) 878 ;; because we do not cancel edit when the user provides a
878 xrow (car x) 879 ;; false reference in it, then we need to check that ref
879 xcol (cdr x)) 880 ;; points to a cell that is within the spreadsheet.
880 (ses-set-cell xrow xcol 'references 881 (setq x (ses-sym-rowcol ref))
881 (delq sym (ses-cell-references xrow xcol))))) 882 (and x
883 (< (setq xrow (car x)) ses--numrows)
884 (< (setq xcol (cdr x)) ses--numcols)
885 (ses-set-cell xrow xcol 'references
886 (delq sym (ses-cell-references xrow xcol))))))
882 ;;Add new ones. Skip ones left over from old list 887 ;;Add new ones. Skip ones left over from old list
883 (dolist (ref newref) 888 (dolist (ref newref)
884 (setq x (ses-sym-rowcol ref) 889 (setq x (ses-sym-rowcol ref))
885 xrow (car x) 890 ;;Do not trust the user, the reference may be outside the spreadsheet
886 xcol (cdr x) 891 (if (and
887 x (ses-cell-references xrow xcol)) 892 x
888 (or (memq sym x) 893 (< (setq xrow (car x)) ses--numrows)
889 (ses-set-cell xrow xcol 'references (cons sym x)))) 894 (< (setq xcol (cdr x)) ses--numcols))
895 (progn
896 (setq x (ses-cell-references xrow xcol))
897 (or (memq sym x)
898 (ses-set-cell xrow xcol 'references (cons sym x))))
899 (cl-pushnew ref not-a-cell-ref-list)))
890 (ses-formula-record formula) 900 (ses-formula-record formula)
891 (ses-set-cell row col 'formula formula)))) 901 (ses-set-cell row col 'formula formula)
902 (and not-a-cell-ref-list
903 (error "Found in formula cells not in spreadsheet: %S" not-a-cell-ref-list)))))
892 904
893 905
894(defun ses-repair-cell-reference-all () 906(defun ses-repair-cell-reference-all ()
@@ -1529,7 +1541,13 @@ by (ROWINCR,COLINCR)."
1529 ;;Relocate this variable, unless it is a named cell 1541 ;;Relocate this variable, unless it is a named cell
1530 (if (eq (get sym 'ses-cell) :ses-named) 1542 (if (eq (get sym 'ses-cell) :ses-named)
1531 sym 1543 sym
1532 (ses-create-cell-symbol row col)) 1544 ;; otherwise, we create the relocated cell symbol because
1545 ;; ses-cell-symbol gives the old symbols, however since
1546 ;; renamed cell are not relocated we keep the relocated
1547 ;; cell old symbol in this case.
1548 (if (eq (get (setq sym (ses-cell-symbol row col)) 'ses-cell) :ses-named)
1549 sym
1550 (ses-create-cell-symbol row col)))
1533 ;;Delete reference to a deleted cell 1551 ;;Delete reference to a deleted cell
1534 nil)))) 1552 nil))))
1535 1553