summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Dominik <carsten.dominik@gmail.com>2009-08-01 07:56:26 +0200
committerCarsten Dominik <carsten.dominik@gmail.com>2009-08-01 07:56:26 +0200
commit2cc99fbb0a1c067235d7425031d8ffddc0668a53 (patch)
treedb7f51ef99eaea1b718f476fe0c4a75c523ce0c5
parent09cccb22b3ed61d612cfabc850a3cd31e22f14e2 (diff)
downloadorg-mode-2cc99fbb0a1c067235d7425031d8ffddc0668a53.tar.gz
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.
-rw-r--r--doc/org.texi8
-rwxr-xr-xlisp/ChangeLog8
-rw-r--r--lisp/org-table.el34
3 files changed, 38 insertions, 12 deletions
diff --git a/doc/org.texi b/doc/org.texi
index 2974ca3..9f5539d 100644
--- a/doc/org.texi
+++ b/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
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
-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
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
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.
Here are a few examples:
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0304aa3..f8c15e5 100755
--- a/lisp/ChangeLog
+++ b/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>
* org-table.el (org-table-cut-region, org-table-copy-region): Work
diff --git a/lisp/org-table.el b/lisp/org-table.el
index 91a92db..5b4c1aa 100644
--- a/lisp/org-table.el
+++ b/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)
(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
: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
"Options concerning table import and export in Org-mode."
:tag "Org Table Import Export"
@@ -2404,9 +2420,13 @@ and TABLE is a vector with line types."
(>= i 0) (< i l)
(not (eq (aref table i) type))
(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)))
(setq n (1- n)))
(if (or (< i 0) (>= i l))