Function: ses-cell-set-formula
ses-cell-set-formula is a byte-compiled function defined in ses.el.gz.
Signature
(ses-cell-set-formula ROW COL FORMULA)
Documentation
Store a new formula for (ROW . COL) and enqueue the cell for
recalculation via post-command-hook. Updates the reference lists for the
cells that this cell refers to. Does not update cell value or reprint the
cell. To avoid inconsistencies, this function is not interruptible, which
means Emacs will crash if FORMULA contains a circular list.
Source Code
;; Defined in /usr/src/emacs/lisp/ses.el.gz
nil))))) ; Make coverage-tester happy.
(defun ses-cell-set-formula (row col formula)
"Store a new formula for (ROW . COL) and enqueue the cell for
recalculation via `post-command-hook'. Updates the reference lists for the
cells that this cell refers to. Does not update cell value or reprint the
cell. To avoid inconsistencies, this function is not interruptible, which
means Emacs will crash if FORMULA contains a circular list."
(let* ((cell (ses-get-cell row col))
(old (ses-cell-formula cell)))
(let ((sym (ses-cell-symbol cell))
(oldref (ses-formula-references old))
(newref (ses-formula-references formula))
(inhibit-quit t)
not-a-cell-ref-list
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.
(dolist (ref oldref)
(unless (memq ref newref)
;; 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.
(when
(and (setq x (ses-sym-rowcol ref))
(< (setq xrow (car x)) ses--numrows)
(< (setq xcol (cdr x)) ses--numcols))
;; Cell reference 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)
;;Do not trust the user, the reference may be outside the spreadsheet
(if (and
(setq x (ses-sym-rowcol ref))
(< (setq xrow (car x)) ses--numrows)
(< (setq xcol (cdr x)) ses--numcols))
(unless (memq sym (setq xref (ses-cell-references xrow xcol)))
;; Cell reference 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)
(and not-a-cell-ref-list
(error "Found in formula cells not in spreadsheet: %S" not-a-cell-ref-list)))))