Function: ses-relocate-formula
ses-relocate-formula is a byte-compiled function defined in ses.el.gz.
Signature
(ses-relocate-formula FORMULA STARTROW STARTCOL ROWINCR COLINCR)
Documentation
Produce a copy of FORMULA where all symbols that refer to cells in row
STARTROW or above, and col STARTCOL or above, are altered by adding ROWINCR
and COLINCR. STARTROW and STARTCOL are 0-based. Example:
(ses-relocate-formula '(+ A1 B2 D3) 1 2 1 -1)
=> (+ A1 B2 C4)
If ROWINCR or COLINCR is negative, references to cells being deleted are
removed. Example:
(ses-relocate-formula '(+ A1 B2 D3) 0 1 0 -1)
=> (+ A1 C3)
Sets ses-relocate-return to delete if cell-references were removed.
Source Code
;; Defined in /usr/src/emacs/lisp/ses.el.gz
(defun ses-relocate-formula (formula startrow startcol rowincr colincr)
"Produce a copy of FORMULA where all symbols that refer to cells in row
STARTROW or above, and col STARTCOL or above, are altered by adding ROWINCR
and COLINCR. STARTROW and STARTCOL are 0-based. Example:
(ses-relocate-formula \\='(+ A1 B2 D3) 1 2 1 -1)
=> (+ A1 B2 C4)
If ROWINCR or COLINCR is negative, references to cells being deleted are
removed. Example:
(ses-relocate-formula \\='(+ A1 B2 D3) 0 1 0 -1)
=> (+ A1 C3)
Sets `ses-relocate-return' to `delete' if cell-references were removed."
(let (rowcol result)
(if (or (atom formula) (eq (car formula) 'quote))
(if (setq rowcol (ses-sym-rowcol formula))
(ses-relocate-symbol formula rowcol
startrow startcol rowincr colincr)
;; Constants pass through as-is.
formula)
(dolist (cur formula)
(setq rowcol (ses-sym-rowcol cur))
(cond
(rowcol
(setq cur (ses-relocate-symbol cur rowcol
startrow startcol rowincr colincr))
(if cur
(push cur result)
;; Reference to a deleted cell. Set a flag in ses-relocate-return.
;; don't change the flag if it's already 'range, since range implies
;; 'delete.
(unless ses-relocate-return
(setq ses-relocate-return 'delete))))
((eq (car-safe cur) 'ses-range)
(setq cur (ses-relocate-range cur startrow startcol rowincr colincr))
(if cur
(push cur result)))
((or (atom cur) (eq (car cur) 'quote))
;; Constants pass through unchanged.
(push cur result))
(t
;; Recursively copy and alter subformulas.
(push (ses-relocate-formula cur startrow startcol
rowincr colincr)
result))))
(nreverse result))))