emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rick Frankel <rick@rickster.com>
To: emacs-orgmode@gnu.org
Subject: Re: [BUG] hline references on left side of table formula
Date: Thu, 07 Nov 2013 10:01:30 -0500	[thread overview]
Message-ID: <602c49099197cd263ad53ad5d0e97ac8@mail.rickster.com> (raw)
In-Reply-To: <87habpthiu.fsf@Rainer.invalid>

[-- Attachment #1: Type: text/plain, Size: 2336 bytes --]

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

[-- Attachment #2: tblref.org --]
[-- Type: text/plain, Size: 3758 bytes --]

* 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:


  reply	other threads:[~2013-11-07 15:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-01  5:32 [BUG] hline references on left side of table formula lompik
2013-11-06  8:23 ` Bastien
2013-11-06 18:50   ` Rick Frankel
2013-11-06 19:57     ` Achim Gratz
2013-11-06 20:14       ` Achim Gratz
2013-11-07 15:01         ` Rick Frankel [this message]
2013-11-07 19:16           ` Achim Gratz
2013-11-07  5:59     ` Michael Brand
2013-11-07 14:40       ` Rick Frankel
  -- strict thread matches above, loose matches on Subject: below --
2013-05-01 17:27 Rick Frankel
2013-09-02  8:10 ` Carsten Dominik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=602c49099197cd263ad53ad5d0e97ac8@mail.rickster.com \
    --to=rick@rickster.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).