Function: org-table-expand-lhs-ranges

org-table-expand-lhs-ranges is a byte-compiled function defined in org-table.el.gz.

Signature

(org-table-expand-lhs-ranges EQUATIONS)

Documentation

Expand list of formulas.

If some of the RHS in the formulas are ranges or a row reference, expand them to individual field equations for each field. This function assumes the table is already analyzed (i.e., using org-table-analyze).

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
(defun org-table-expand-lhs-ranges (equations)
  "Expand list of formulas.
If some of the RHS in the formulas are ranges or a row reference,
expand them to individual field equations for each field.  This
function assumes the table is already analyzed (i.e., using
`org-table-analyze')."
  (let (res)
    (dolist (e equations (nreverse res))
      (let ((lhs (car e))
	    (rhs (cdr e)))
	(cond
	 ((string-match-p "\\`@[-+0-9]+\\$-?[0-9]+\\'" lhs)
	  ;; This just refers to one fixed field.
	  (push e res))
	 ((string-match-p "\\`[a-zA-Z][_a-zA-Z0-9]*\\'" lhs)
	  ;; This just refers to one fixed named field.
	  (push e res))
	 ((string-match-p "\\`\\$[0-9]+\\'" lhs)
	  ;; Column formulas are treated specially and are not
	  ;; expanded.
	  (push e res))
	 ((string-match "\\`@[0-9]+\\'" lhs)
	  (dotimes (ic org-table-current-ncol)
	    (push (cons (propertize (format "%s$%d" lhs (1+ ic)) :orig-eqn e)
			rhs)
		  res)))
	 (t
	  (let* ((range (org-table-get-range
			 lhs org-table-current-begin-pos 1 nil 'corners))
		 (r1 (org-table-line-to-dline (nth 0 range)))
		 (c1 (nth 1 range))
		 (r2 (org-table-line-to-dline (nth 2 range) 'above))
		 (c2 (nth 3 range)))
	    (cl-loop for ir from r1 to r2 do
		     (cl-loop for ic from c1 to c2 do
			      (push (cons (propertize
					   (format "@%d$%d" ir ic) :orig-eqn e)
					  rhs)
				    res))))))))))