Browse Source

Tables: Relative row references may now cross hlines

A relative row reference like @-1 in a table may now reach across a
horizontal separator line.  I hope this will not break any important
tables out there, but I think it is the right thing to do.

The original reason for not-crossing was to implement running
averages of one column in the next.  This can now be done using field
formulas near the beginning and end of the column, and a column
formula for the central part.

See the variable `org-table-relative-ref-may-cross-hline' for more
details.
Carsten Dominik 16 years ago
parent
commit
2cc99fbb0a
3 changed files with 38 additions and 12 deletions
  1. 3 5
      doc/org.texi
  2. 8 0
      lisp/ChangeLog
  3. 27 7
      lisp/org-table.el

+ 3 - 5
doc/org.texi

@@ -2072,9 +2072,7 @@ starts with a hline above the header, it does not count.}, @samp{II} to
 the second, etc@.  @samp{-I} refers to the first such line above the
 the second, etc@.  @samp{-I} refers to the first such line above the
 current line, @samp{+I} to the first such line below the current line.
 current line, @samp{+I} to the first such line below the current line.
 You can also write @samp{III+2} which is the second data line after the
 You can also write @samp{III+2} which is the second data line after the
-third hline in the table.  Relative row numbers like @samp{-3} will not
-cross hlines if the current line is too close to the hline.  Instead,
-the value directly at the hline is used.
+third hline in the table.
 
 
 @samp{0} refers to the current row and column.  Also, if you omit
 @samp{0} refers to the current row and column.  Also, if you omit
 either the column or the row part of the reference, the current
 either the column or the row part of the reference, the current
@@ -2087,8 +2085,8 @@ Org's references with @emph{signed} numbers are floating
 references because the same reference operator can reference different
 references because the same reference operator can reference different
 fields depending on the field being calculated by the formula.
 fields depending on the field being calculated by the formula.
 
 
-As a special case, references like @samp{$LR5} and @samp{$LR12} can be used to
-refer in a stable way to the 5th and 12th field in the last row of the
+As a special case, references like @samp{$LR5} and @samp{$LR12} can be used
+to refer in a stable way to the 5th and 12th field in the last row of the
 table.
 table.
 
 
 Here are a few examples:
 Here are a few examples:

+ 8 - 0
lisp/ChangeLog

@@ -1,3 +1,11 @@
+2009-08-01  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-table.el (org-table-error-on-row-ref-crossing-hline):
+	Variable made obsolete.
+	(org-table-relative-ref-may-cross-hline): New option.
+	(org-table-find-row-type): Honow the new option
+	`org-table-relative-ref-may-cross-hline'.
+
 2009-07-31  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-07-31  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org-table.el (org-table-cut-region, org-table-copy-region): Work
 	* org-table.el (org-table-cut-region, org-table-copy-region): Work

+ 27 - 7
lisp/org-table.el

@@ -247,13 +247,29 @@ Automatically means, when TAB or RET or C-c C-c are pressed in the line."
   :type 'boolean)
   :type 'boolean)
 
 
 (defcustom org-table-error-on-row-ref-crossing-hline t
 (defcustom org-table-error-on-row-ref-crossing-hline t
-  "Non-nil means, a relative row reference that tries to cross a hline errors.
-When nil, the reference will silently be to the field just next to the hline.
-Coming from below, it will be the field below the hline, coming from
-above, it will be the field above the hline."
+  "OBSOLETE VARIABLE, please see `org-table-relative-ref-may-cross-hline'."
   :group 'org-table
   :group 'org-table
   :type 'boolean)
   :type 'boolean)
 
 
+(defcustom org-table-relative-ref-may-cross-hline t
+  "Non-nil means, reltive formula references may cross hlines.
+Here are the allowed values:
+
+nil    Relative references may not cross hlines.  They will reference the
+       field next to the hline instead.  Coming from below, the reference
+       will be to the field below the hline.  Coming from above, it will be
+       to the field above.
+t      Relative references may cros hlines.
+error  An attempt to cross a hline will throw an error.
+
+It is probably good to never set this variable to nil, for the sake of
+portability of tables."
+  :group 'org-table-calculation
+  :type '(choice
+	  (const :tag "Allow to cross" t)
+	  (const :tag "Stick to hline" nil)
+	  (const :tag "Error on attempt to cross" error)))
+
 (defgroup org-table-import-export nil
 (defgroup org-table-import-export nil
   "Options concerning table import and export in Org-mode."
   "Options concerning table import and export in Org-mode."
   :tag "Org Table Import Export"
   :tag "Org Table Import Export"
@@ -2404,9 +2420,13 @@ and TABLE is a vector with line types."
 		  (>= i 0) (< i l)
 		  (>= i 0) (< i l)
 		  (not (eq (aref table i) type))
 		  (not (eq (aref table i) type))
 		  (if (and relative (eq (aref table i) 'hline))
 		  (if (and relative (eq (aref table i) 'hline))
-		      (if org-table-error-on-row-ref-crossing-hline
-			  (error "Row descriptor %s used in line %d crosses hline" desc cline)
-			(progn (setq i (- i (if backwards -1 1)) n 1) nil))
+		      (cond
+		       ((eq org-table-relative-ref-may-cross-hline t) t)
+		       ((eq org-table-relative-ref-may-cross-hline 'error)
+			(error "Row descriptor %s used in line %d crosses hline" desc cline))
+		       (t (setq i (- i (if backwards -1 1))
+				n 1)
+			  nil))
 		    t)))
 		    t)))
       (setq n (1- n)))
       (setq n (1- n)))
     (if (or (< i 0) (>= i l))
     (if (or (< i 0) (>= i l))