Function: ses-calculate-cell

ses-calculate-cell is a byte-compiled function defined in ses.el.gz.

Signature

(ses-calculate-cell ROW COL FORCE)

Documentation

Calculate and print the value for cell (ROW,COL) using the cell's formula function and print functions, if any. Result is nil for normal operation, or the error signal if the formula or print function failed. The old value is left unchanged if it was *skip* and the new value is nil.
  Any cells that depend on this cell are queued for update after the end of
processing for the current keystroke, unless the new value is the same as the old and FORCE is nil.

Source Code

;; Defined in /usr/src/emacs/lisp/ses.el.gz
(defun ses-calculate-cell (row col force)
  "Calculate and print the value for cell (ROW,COL) using the cell's formula
function and print functions, if any.  Result is nil for normal operation, or
the error signal if the formula or print function failed.  The old value is
left unchanged if it was *skip* and the new value is nil.
  Any cells that depend on this cell are queued for update after the end of
processing for the current keystroke, unless the new value is the same as
the old and FORCE is nil."
  (let ((cell (ses-get-cell row col))
	cycle-error formula-error printer-error)
    (let ((oldval  (ses-cell-value   cell))
	  (formula (ses-cell-formula cell))
	  newval
	  this-cell-Dijkstra-attempt+1)
      (when (eq (car-safe formula) 'ses-safe-formula)
	(setq formula (ses-safe-formula (cadr formula)))
	(ses-set-cell row col 'formula formula))
      (condition-case sig
	  (setq newval (eval formula t))
	(error
	 ;; Variable `sig' can't be nil.
	 (nconc sig (list (ses-cell-symbol cell)))
	 (setq formula-error sig
	       newval        '*error*)))
      (if (and (not newval) (eq oldval '*skip*))
	  ;; Don't lose the *skip* --- previous field spans this one.
	  (setq newval '*skip*))
      (catch 'cycle
	(when (or force (not (eq newval oldval)))
	  (cl-pushnew (cons row col) ses--deferred-write :test #'equal) ; In case force=t.
          (ses--letref (pget pset)
              (ses-cell-property :ses-Dijkstra-attempt cell)
            (let ((this-cell-Dijkstra-attempt (pget)))
              (if (null this-cell-Dijkstra-attempt)
                  (pset
                   (setq this-cell-Dijkstra-attempt
                         (cons ses--Dijkstra-attempt-nb 0)))
                (unless (= ses--Dijkstra-attempt-nb
                           (car this-cell-Dijkstra-attempt))
                  (setcar this-cell-Dijkstra-attempt ses--Dijkstra-attempt-nb)
                  (setcdr this-cell-Dijkstra-attempt 0)))
              (setq this-cell-Dijkstra-attempt+1
                    (1+ (cdr this-cell-Dijkstra-attempt)))))
	  (ses-set-cell row col 'value newval)
	  (dolist (ref (ses-cell-references cell))
	    (cl-pushnew ref ses--deferred-recalc)
            (ses--letref (pget pset)
                (let ((ref-rowcol (ses-sym-rowcol ref)))
                  (ses-cell-property
                   :ses-Dijkstra-attempt
                   (car ref-rowcol) (cdr ref-rowcol)))
              (let ((ref-cell-Dijkstra-attempt (pget)))

                (if (null ref-cell-Dijkstra-attempt)
                    (pset
                     (setq ref-cell-Dijkstra-attempt
                           (cons ses--Dijkstra-attempt-nb
                                 this-cell-Dijkstra-attempt+1)))
                  (if (= (car ref-cell-Dijkstra-attempt) ses--Dijkstra-attempt-nb)
                      (setcdr ref-cell-Dijkstra-attempt
                              (max (cdr ref-cell-Dijkstra-attempt)
                                   this-cell-Dijkstra-attempt+1))
                    (setcar ref-cell-Dijkstra-attempt ses--Dijkstra-attempt-nb)
                    (setcdr ref-cell-Dijkstra-attempt
                            this-cell-Dijkstra-attempt+1)))))

	    (when (> this-cell-Dijkstra-attempt+1 ses--Dijkstra-weight-bound)
	      ;; Update print of this cell.
	      (throw 'cycle (setq formula-error
				  `(error ,(format "Found cycle on cells %S"
						   (ses-cell-symbol cell)))
				  cycle-error formula-error)))))))
    (setq printer-error (ses-print-cell row col))
    (or
     (and cycle-error
	  (error (error-message-string cycle-error)))
     formula-error printer-error)))