Make table formulas error when a relative row reference tries to cross hline.

Tassilo Horn asked for this, because he finds the default behavior of
silently choosing a different row too confusing.  I actually do agree.

The main use of this feature was running averages, if you need this
feature, you can customize the variable
`org-table-error-on-row-ref-crossing-hline'.
This commit is contained in:
Carsten Dominik 2008-12-05 13:07:17 +01:00
parent 520ff98609
commit 575dcb3d3b
3 changed files with 42 additions and 5 deletions

View File

@ -18,6 +18,23 @@
** Overview
** Incompatible Changes
*** Relative row references crossing hlines now throw an error
Relative row references in tables look like this: "@-4" which
means the forth row above this one. These row references are
not allowed to cross horizontal separator lines (hlines). So
far, when a row reference violates this policy, Org would
silently choose the field just next to the hline.
Tassilo Horn pointed out that this kind of hidden magic is
actually confusing and may cause incorrect formulas, and I do
agree. Therefore, trying to cross a hline with a relative
reference will now throw an error.
If you need the old behavior, customize the variable
`org-table-error-on-row-ref-crossing-hline'.
** Details
*** New relative timer to support timed notes

View File

@ -1,5 +1,11 @@
2008-12-05 Carsten Dominik <carsten.dominik@gmail.com>
* org-table.el (org-find-row-type): New arguments DESC and CLINE,
for better error messages.
(org-table-get-descriptor-line): Supply the new arguments to
`org-find-row-type'.
(org-table-error-on-row-ref-crossing-hline): New option.
* org.el (org-target-link-regexp): Make buffer-local.
(org-move-subtree-down): Fix bug with trees at beginning of
buffer.

View File

@ -244,6 +244,14 @@ Automatically means, when TAB or RET or C-c C-c are pressed in the line."
:group 'org-table-calculation
: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."
:group 'org-table
:type 'boolean)
(defgroup org-table-import-export nil
"Options concerning table import and export in Org-mode."
:tag "Org Table Import Export"
@ -2288,23 +2296,29 @@ and TABLE is a vector with line types."
(if (and (not hn) on (not odir))
(error "should never happen");;(aref org-table-dlines on)
(if (and hn (> hn 0))
(setq i (org-find-row-type table i 'hline (equal hdir "-") nil hn)))
(setq i (org-find-row-type table i 'hline (equal hdir "-") nil hn
cline desc)))
(if on
(setq i (org-find-row-type table i 'dline (equal odir "-") rel on)))
(setq i (org-find-row-type table i 'dline (equal odir "-") rel on
cline desc)))
(+ bline i)))))
(defun org-find-row-type (table i type backwards relative n)
(defun org-find-row-type (table i type backwards relative n cline desc)
"FIXME: Needs more documentation."
(let ((l (length table)))
(while (> n 0)
(while (and (setq i (+ i (if backwards -1 1)))
(>= i 0) (< i l)
(not (eq (aref table i) type))
(if (and relative (eq (aref table i) 'hline))
(progn (setq i (- i (if backwards -1 1)) n 1) nil)
(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))
t)))
(setq n (1- n)))
(if (or (< i 0) (>= i l))
(error "Row descriptor leads outside table")
(error "Row descriptor %s used in line %d leads outside table"
desc cline)
i)))
(defun org-rewrite-old-row-references (s)