On 2013-11-06 15:14, Achim Gratz wrote:
Achim Gratz writes:
[...]
with these formulas:
#+TBLFM: $=vsum(@-II..@-I)
whoops, press C-c C-c in the wrong buffer.
I meant these formulas:
#+TBLFM: @$=vsum(@-II..@-I)
#+TBLFM: @II=vsum(@-II..@-I)
#+TBLFM: @III=vsum(@-II..@-I)
#+TBLFM: @IIII=vsum(@-II..@-I)
#+TBLFM: @II..$2=vsum(@-II..@-I)
#+TBLFM: @III..$2=vsum(@-II..@-I)
#+TBLFM: @IIII..$2=vsum(@-II..@-I)
#+TBLFM: @II+1..@II$2=vsum(@-II..@-I)
#+TBLFM: @II$2..@II+1$2=vsum(@-II..@-I)
Some of the results are useful when your table has a certain, even
though in general this does the wrong thing as Carsten said. I'm not
really having an opinion on whether this should be an error (as your
previous patch does, which should then add a correction to the test
that
is now failing) or if some / all of this should stay allowed until
somebody musters the time to fix it properly (I think this would amount
to re-implementing a good part of what is org-table).
Ok, i see what's happening in your examples (a testing org file
attached), though i question the usefullness of most of the results ;).
The updated patch attached to the previous email (fixed as pointed out
by michael):
--- a/lisp/org-table.el
+++ b/lisp/org-table.el
@@ -3016,8 +3016,9 @@ known that the table will be realigned a little
later anyway."
;; Insert constants in all formulas
(setq eqlist
(mapcar (lambda (x)
- (if (string-match "^@-?I+" (car x))
- (user-error "Can't assign to hline relative reference"))
+ (if (and (string-match "^@-?I+" (car x))
+ (not (string-match "\\.\\.@" (car x))))
+ (user-error "Can't assign to hline relative reference
without a range specification."))
(when (string-match "\\`$[<>]" (car x))
(setq lhs1 (car x))
(setq x (cons (substring
Both fixes the testing issue and allows what seems to me to be the
most relevant use-case.
I have no real position on whether the best solution is to back out
the change, or modify it as above to make the test pass and allow the
logical usecase.
If the first, I think it would be useful for the documentation to
(somehow) explain what happens if an explicit column specificaton is
made without a corresponding range.
Please chime in on which patch should be applied.
rick
* Code
:PROPERTIES:
:eval: never
:END:
#+name: table
#+BEGIN_SRC emacs-lisp :results silent :eval yes
"| a | b |
|---+---|
| w | 1 |
| x | 2 |
|---+---|
| | |
| | |
|---+---|
| y | 3 |
| z | 4 |
|---+---|
| | |"
#+END_SRC
#+name: expand-tables
#+BEGIN_SRC emacs-lisp
(save-excursion
(while (re-search-forward org-table-TBLFM-begin-regexp)
(org-table-calc-current-TBLFM)))
#+END_SRC
#+name: generate-tables
#+BEGIN_SRC emacs-lisp :var table=table :results wrap
(mapconcat
(lambda (fm)
(mapconcat
'identity (list (concat "**" (substring fm 8)) table fm) "\n"))
(list "#+TBLFM: @$=vsum(@-II..@-I)"
"#+TBLFM: @II=vsum(@-II..@-I)"
"#+TBLFM: @III=vsum(@-II..@-I)"
"#+TBLFM: @IIII=vsum(@-II..@-I)"
"#+TBLFM: @II..$2=vsum(@-II..@-I)"
"#+TBLFM: @III..$2=vsum(@-II..@-I)"
"#+TBLFM: @IIII..$2=vsum(@-II..@-I)"
"#+TBLFM: @II+1..@II$2=vsum(@-II..@-I)"
"#+TBLFM: @II$2..@II+1$2=vsum(@-II..@-I)") "\n")
#+END_SRC
* Eval me! (=\C-c\C-v\C-s=)
:PROPERTIES:
:ID: EVAL-ME
:END:
#+name: call-generate
#+call: generate-tables[:eval yes](table=table) :results wrap
#+call: expand-tables[:eval yes]() :results silent
#+RESULTS: call-generate
:RESULTS:
** @$=vsum(@-II..@-I)
| a | b |
|-------+---|
| w | 1 |
| x | 2 |
|-------+---|
| | |
| | |
|-------+---|
| y | 3 |
| z | 4 |
|-------+---|
| y + z | |
#+TBLFM: @$=vsum(@-II..@-I)
** @II=vsum(@-II..@-I)
| a | b |
|-------------------------------+---|
| w | 1 |
| x | 2 |
|-------------------------------+---|
| w + x | |
| w + x | |
|-------------------------------+---|
| w + x + w + x | 3 |
| w + x + w + x | 4 |
|-------------------------------+---|
| w + x + w + x + w + x + w + x | |
#+TBLFM: @II=vsum(@-II..@-I)
** @III=vsum(@-II..@-I)
| a | b |
|---+---|
| w | 1 |
| x | 2 |
|---+---|
| | |
| | |
|---+---|
| 0 | 3 |
| 0 | 4 |
|---+---|
| 0 | |
#+TBLFM: @III=vsum(@-II..@-I)
** @IIII=vsum(@-II..@-I)
| a | b |
|-------+---|
| w | 1 |
| x | 2 |
|-------+---|
| | |
| | |
|-------+---|
| y | 3 |
| z | 4 |
|-------+---|
| y + z | |
#+TBLFM: @IIII=vsum(@-II..@-I)
** @II..$2=vsum(@-II..@-I)
| a | b |
|-------------------------------+----|
| w | 1 |
| x | 2 |
|-------------------------------+----|
| w + x | 3 |
| w + x | 3 |
|-------------------------------+----|
| w + x + w + x | 6 |
| w + x + w + x | 6 |
|-------------------------------+----|
| w + x + w + x + w + x + w + x | 12 |
#+TBLFM: @II..$2=vsum(@-II..@-I)
** @III..$2=vsum(@-II..@-I)
| a | b |
|---+---|
| w | 1 |
| x | 2 |
|---+---|
| | |
| | |
|---+---|
| 0 | 0 |
| 0 | 0 |
|---+---|
| 0 | 0 |
#+TBLFM: @III..$2=vsum(@-II..@-I)
** @IIII..$2=vsum(@-II..@-I)
| a | b |
|-------+---|
| w | 1 |
| x | 2 |
|-------+---|
| | |
| | |
|-------+---|
| y | 3 |
| z | 4 |
|-------+---|
| y + z | 7 |
#+TBLFM: @IIII..$2=vsum(@-II..@-I)
** @II+1..@II$2=vsum(@-II..@-I)
| a | b |
|-------+---|
| w | 1 |
| x | 2 |
|-------+---|
| w + x | 3 |
| | |
|-------+---|
| y | 3 |
| z | 4 |
|-------+---|
| | |
#+TBLFM: @II+1..@II$2=vsum(@-II..@-I)
** @II$2..@II+1$2=vsum(@-II..@-I)
| a | b |
|---+---|
| w | 1 |
| x | 2 |
|---+---|
| | 3 |
| | |
|---+---|
| y | 3 |
| z | 4 |
|---+---|
| | |
#+TBLFM: @II$2..@II+1$2=vsum(@-II..@-I)
:END: