From 38ad5df8ab16713f3e32d1c2106f2b1cf1e6ea42 Mon Sep 17 00:00:00 2001 From: Michael Brand Date: Sat, 4 Jan 2014 16:25:42 +0100 Subject: [PATCH 2/2] TBLFM remote ref: Add indirection of name or ID * doc/org.texi (References): Add description for indirection of NAME-OR-ID. * lisp/org-table.el (org-table-eval-formula): Make use of `org-table-remote-reference-indirection'. (org-table-remote-reference-indirection): New function. * testing/lisp/test-org-table.el (test-org-table/remote-reference-indirect): Change to use remote reference indirection. --- doc/org.texi | 6 ++++++ lisp/org-table.el | 25 +++++++++++++++++++++++++ testing/lisp/test-org-table.el | 18 ++++-------------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/doc/org.texi b/doc/org.texi index bf5dafd..f710971 100644 --- a/doc/org.texi +++ b/doc/org.texi @@ -2630,6 +2630,12 @@ table in that entry. REF is an absolute field or range reference as described above for example @code{@@3$3} or @code{$somename}, valid in the referenced table. +Indirection of NAME-OR-ID: When NAME-OR-ID has the format @code{@@ROW$COLUMN} +it will be substituted with the name or ID found in this field of the current +table. For example @code{remote($1, @@>$2)} => @code{remote(year_2013, +@@>$1)}. The format @code{B3} is not supported because it can not be +distinguished from a plain table name or ID. + @node Formula syntax for Calc @subsection Formula syntax for Calc @cindex formula syntax, Calc diff --git a/lisp/org-table.el b/lisp/org-table.el index 36478f8..8c823d2 100644 --- a/lisp/org-table.el +++ b/lisp/org-table.el @@ -2657,6 +2657,7 @@ not overwrite the stored one." ;; Check for old vertical references (setq form (org-table-rewrite-old-row-references form)) ;; Insert remote references + (setq form (org-table-remote-reference-indirection form)) (while (string-match "\\$2)\" => \"remote(year_2013, @>$1)\". +This indirection works only with the format @ROW$COLUMN. The +format \"B3\" is not supported because it can not be +distinguished from a plain table name or ID." + (while (string-match (concat + ;; Same as in `org-table-eval-formula'. + "\\$1) :: " - "@3$2 = remote(2013, @>$1) :: " - "@>$2 = vsum(@I..@II)") + "#+TBLFM: @<<$2..@>>$2 = remote($<, @>$1) :: @>$2 = vsum(@I..@II)" ;; Lisp formula - (concat "#+TBLFM: " - "@2$2 = '(identity remote(2012, @>$1)); N :: " - "@3$2 = '(identity remote(2013, @>$1)); N :: " + (concat "#+TBLFM: @<<$2..@>>$2 = '(identity remote($<, @>$1)); N :: " "@>$2 = '(+ @I..@II); N")) ;; Read several remote references from same row @@ -863,14 +858,9 @@ See also `test-org-table/copy-field'." ") 1 ;; Calc formula - (concat "#+TBLFM: " - "@2$2 = remote(2012, @>$1) :: " - "@2$3 = remote(2013, @>$1) :: " - "@2$> = vsum($<<..$>>)") + "#+TBLFM: @2$<<..@2$>> = remote(@<, @>$1) :: @2$> = vsum($<<..$>>)" ;; Lisp formula - (concat "#+TBLFM: " - "@2$2 = '(identity remote(2012, @>$1)); N :: " - "@2$3 = '(identity remote(2013, @>$1)); N :: " + (concat "#+TBLFM: @2$<<..@2$>> = '(identity remote(@<, @>$1)); N :: " "@2$> = '(+ $<<..$>>); N")))) (ert-deftest test-org-table/org-at-TBLFM-p () -- 1.7.12.4 (Apple Git-37)