Function: ses-relocate-range

ses-relocate-range is a byte-compiled function defined in ses.el.gz.

Signature

(ses-relocate-range RANGE STARTROW STARTCOL ROWINCR COLINCR)

Documentation

Relocate one RANGE, of the form (ses-range MIN MAX). Cells starting at (STARTROW,STARTCOL) are being shifted by (ROWINCR,COLINCR). Result is the new range, or nil if the entire range is deleted. If new rows are being added just beyond the end of a row range, or new columns just beyond a column range, the new rows/columns will be added to the range. Sets ses-relocate-return if the range was altered.

Source Code

;; Defined in /usr/src/emacs/lisp/ses.el.gz
(defun ses-relocate-range (range startrow startcol rowincr colincr)
  "Relocate one RANGE, of the form (ses-range MIN MAX).  Cells starting
at (STARTROW,STARTCOL) are being shifted by (ROWINCR,COLINCR).  Result is the
new range, or nil if the entire range is deleted.  If new rows are being added
just beyond the end of a row range, or new columns just beyond a column range,
the new rows/columns will be added to the range.  Sets `ses-relocate-return'
if the range was altered."
  (let* ((minorig   (cadr range))
	 (minrowcol (ses-sym-rowcol minorig))
	 (min       (ses-relocate-symbol minorig minrowcol
					 startrow startcol
					 rowincr colincr))
	 (maxorig   (nth 2 range))
	 (maxrowcol (ses-sym-rowcol maxorig))
	 (max       (ses-relocate-symbol maxorig maxrowcol
					 startrow startcol
					 rowincr colincr))
	 field)
    (cond
     ((and (not min) (not max))
      (setq range nil)) ; The entire range is deleted.
     ((zerop colincr)
      ;; Inserting or deleting rows.
      (setq field 'car)
      (if (not min)
	  ;; Chopped off beginning of range.
	  (setq min           (ses-create-cell-symbol startrow (cdr minrowcol))
		ses-relocate-return 'range))
      (if (not max)
	  (if (> rowincr 0)
	      ;; Trying to insert a nonexistent row.
	      (setq max (ses-create-cell-symbol (1- ses--numrows)
						(cdr minrowcol)))
	    ;; End of range is being deleted.
	    (setq max (ses-create-cell-symbol (1- startrow) (cdr minrowcol))
		  ses-relocate-return 'range))
	(and (> rowincr 0)
	     (= (car maxrowcol) (1- startrow))
	     (= (cdr minrowcol) (cdr maxrowcol))
	     ;; Insert after ending row of vertical range --- include it.
	     (setq max (ses-create-cell-symbol (+ startrow rowincr -1)
					       (cdr maxrowcol))))))
     (t
      ;; Inserting or deleting columns.
      (setq field 'cdr)
      (if (not min)
	  ;; Chopped off beginning of range.
	  (setq min          (ses-create-cell-symbol (car minrowcol) startcol)
		ses-relocate-return 'range))
      (if (not max)
	  (if (> colincr 0)
	      ;; Trying to insert a nonexistent column.
	      (setq max (ses-create-cell-symbol (car maxrowcol)
						(1- ses--numcols)))
	    ;; End of range is being deleted.
	    (setq max (ses-create-cell-symbol (car maxrowcol) (1- startcol))
		  ses-relocate-return 'range))
	(and (> colincr 0)
	     (= (cdr maxrowcol) (1- startcol))
	     (= (car minrowcol) (car maxrowcol))
	     ;; Insert after ending column of horizontal range --- include it.
	     (setq max (ses-create-cell-symbol (car maxrowcol)
						  (+ startcol colincr -1)))))))
    (when range
      (if (/= (- (funcall field maxrowcol)
		 (funcall field minrowcol))
	      (- (funcall field (ses-sym-rowcol max))
		 (funcall field (ses-sym-rowcol min))))
	  ;; This range has changed size.
	  (setq ses-relocate-return 'range))
      `(ses-range ,min ,max ,@(cdddr range)))))