浏览代码

Tables: Introduce field coordinates for formulas, improve docs

Patch by Michael Brand
Carsten Dominik 15 年之前
父节点
当前提交
7dd154cc2a
共有 4 个文件被更改,包括 46 次插入5 次删除
  1. 5 0
      doc/ChangeLog
  2. 22 5
      doc/org.texi
  3. 5 0
      lisp/ChangeLog
  4. 14 0
      lisp/org-table.el

+ 5 - 0
doc/ChangeLog

@@ -1,3 +1,8 @@
+2010-03-14  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.texi (The spreadsheet): Mention the formula editor.
+	(References): Document field coordinates.
+
 2010-03-05  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* pdflayout.sty: New file.

+ 22 - 5
doc/org.texi

@@ -1928,11 +1928,13 @@ Orgtbl mode, including spreadsheet capabilities.  For details, see
 
 The table editor makes use of the Emacs @file{calc} package to implement
 spreadsheet-like capabilities.  It can also evaluate Emacs Lisp forms to
-derive fields from other fields.  While fully featured, Org's
-implementation is not identical to other spreadsheets.  For example,
-Org knows the concept of a @emph{column formula} that will be
-applied to all non-header fields in a column without having to copy the
-formula to each relevant field.
+derive fields from other fields.  While fully featured, Org's implementation
+is not identical to other spreadsheets.  For example, Org knows the concept
+of a @emph{column formula} that will be applied to all non-header fields in a
+column without having to copy the formula to each relevant field.  There is
+also a formula debugger, and a formula editor with features for highlighting
+fields in the table corresponding to the references at the point in the
+formula, moving these references by arrow keys
 
 @menu
 * References::                  How to refer to another field or range
@@ -2040,6 +2042,21 @@ suppressed, so that the vector contains only the non-empty fields (but
 see the @samp{E} mode switch below).  If there are no non-empty fields,
 @samp{[0]} is returned to avoid syntax errors in formulas.
 
+@subsubheading Field coordinates
+@cindex field coordinates
+@cindex coordinates, of field
+@cindex row, of field coordinates
+@cindex column, of field coordinates
+
+For Calc formulas and Lisp formulas @code{@@#} and @code{$#} can be used to
+get the row or column number of the field where the formula result goes.
+The traditional Lisp formula equivalents are @code{org-table-current-dline}
+and @code{org-table-current-column}.  Example:
+
+@example
+if(@@# % 2, $#, string(""))      @r{column number on odd lines only}
+@end example
+
 @subsubheading Named references
 @cindex named references
 @cindex references, named

+ 5 - 0
lisp/ChangeLog

@@ -1,3 +1,8 @@
+2010-03-14  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-table.el (org-table-eval-formula): Replace $# and @# by
+	current column and row number.
+
 2010-03-12  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org.el (org-set-property, org-delete-property): Go back to

+ 14 - 0
lisp/org-table.el

@@ -2245,6 +2245,20 @@ not overwrite the stored one."
 	(setq form (copy-sequence formula)
 	      lispp (and (> (length form) 2)(equal (substring form 0 2) "'(")))
 	(if (and lispp literal) (setq lispp 'literal))
+
+	;; Insert row and column number of formula result field
+	(while (string-match "[@$]#" form)
+	  (setq form
+		(replace-match
+		 (format "%d"
+			 (save-match-data
+			   (if (equal (substring form (match-beginning 0)
+						 (1+ (match-beginning 0)))
+				      "@")
+			       (org-table-current-dline)
+			     (org-table-current-column))))
+		 t t form)))
+
 	;; Check for old vertical references
 	(setq form (org-table-rewrite-old-row-references form))
 	;; Insert remote references