emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] org table with auto-incrementing numbers in a column


From: Derek Feichtinger
Subject: Re: [O] org table with auto-incrementing numbers in a column
Date: Tue, 16 Feb 2016 09:16:38 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Hi


> >
> > Try this
> >
> >   | N |   |
> >   |---+---|
> >   |   |   |
> >   |   |   |
> >   |   |   |
> >   |   |   |
> >   #+TBLFM: <at>$1..<at>>$1= <at>-1 + 1:: <at>2$1=1
> >

Sorry, I had a typo from copying and replacing <at> in my formula

should be


  | N |   |
  |---+---|
  | 1 |   |
  | 2 |   |
  | 3 |   |
  | 4 |   |
  #+TBLFM: <at>3$1..<at>>$1= <at>-1 + 1:: <at>2$1=1


> 
> I don't know exactly why  "N" is *not* erased but the following is
> working for me (org 8.2.10).

Hmmm... I just tested. Seems that org is treating the cells before the first
horizontal separator line as special... nice. But I seem to remember that
this was not always like this.

This made me now investigate more closely, using the formula debugger (C-c
{) for investigating the original formula.

When I use this formula

#+TBLFM: $1= @-1 + 1:: @2$1=1

Then org will first fill this part of the table (starting at cell <at>2$1)

  | N |   |
  |---+---|
  |   |   |
  | 1 |   |
  | 2 |   |
  | 3 |   |
  #+TBLFM: $1= <at>-1 + 1:: <at>2$1=1

Then it will execute the second formula, which sets the value in row 2:

  | N |   |
  |---+---|
  | 1 |   |
  | 1 |   |
  | 2 |   |
  | 3 |   |

Only upon a second evaluation of the whole table, it will arrive at

  | N |   |
  |---+---|
  | 1 |   |
  | 2 |   |
  | 3 |   |
  | 4 |   |

So, this is one of the cases where one needs to carry our iterations until
the table stays constant (can use org-table-iterate).

I also tried the same with changing the order of the two formulas. Seems
that the row formula always is executed first. So, at least this is
consistent. Why it starts at row 3 one would need to look up in the source...


> 
> | N     |
> |-------|
> |     1 |
> |     2 |
> |     3 |
> |     4 |
> |     5 |
> #+TBLFM: $1= <at> #-1
> 
> > Placing point on the TBLFM line and doing C-c C-c should recalculate the
> > whole table.

That formula works fine. It's just a difference in functionality.. the above
formula calculates a value based on the numeric position of the current row,
while the other formula looks up the value above the current row.

Cheers,
Derek






reply via email to

[Prev in Thread] Current Thread [Next in Thread]