Function: org-table-formula-handle-first/last-rc
org-table-formula-handle-first/last-rc is a byte-compiled function
defined in org-table.el.gz.
Signature
(org-table-formula-handle-first/last-rc S)
Documentation
Replace @<, @>, $<, $> with first/last row/column of the table.
So @< and $< will always be replaced with @1 and $1, respectively. The advantage of these special markers are that structure editing of the table will not change them, while @1 and $1 will be modified when a line/row is swapped out of that privileged position. So for formulas that use a range of rows or columns, it may often be better to anchor the formula with "I" row markers, or to offset from the borders of the table using the @< @> $< $> makers.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org-table.el.gz
(defun org-table-formula-handle-first/last-rc (s)
"Replace @<, @>, $<, $> with first/last row/column of the table.
So @< and $< will always be replaced with @1 and $1, respectively.
The advantage of these special markers are that structure editing of
the table will not change them, while @1 and $1 will be modified
when a line/row is swapped out of that privileged position. So for
formulas that use a range of rows or columns, it may often be better
to anchor the formula with \"I\" row markers, or to offset from the
borders of the table using the @< @> $< $> makers."
(let (n nmax len char (start 0))
(while (string-match "\\([@$]\\)\\(<+\\|>+\\)\\|\\(remote([^)]+)\\)"
s start)
(if (match-end 3)
(setq start (match-end 3))
(setq nmax (if (equal (match-string 1 s) "@")
(1- (length org-table-dlines))
org-table-current-ncol)
len (- (match-end 2) (match-beginning 2))
char (string-to-char (match-string 2 s))
n (if (= char ?<)
len
(- nmax len -1)))
(if (or (< n 1) (> n nmax))
(user-error "Reference \"%s\" in expression \"%s\" points outside table"
(match-string 0 s) s))
(setq start (match-beginning 0))
(setq s (replace-match (format "%s%d" (match-string 1 s) n) t t s)))))
s)