all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* org table with auto-incrementing numbers in a column
@ 2016-02-16  4:36 Kaushal Modi
  2016-02-16  6:22 ` Derek Feichtinger
  0 siblings, 1 reply; 7+ messages in thread
From: Kaushal Modi @ 2016-02-16  4:36 UTC (permalink / raw)
  To: emacs-org list

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

Hi,

I am trying to get auto-incrementing numbers in the first column in an org
table. The goal is to recalculate the numbers after adding/removing rows.

I checked out the org FAQ:
http://orgmode.org/worg/org-faq.html#fill-table-column-with-incremental-numbers

But I am still not getting it to work as I need to.

Below is the minimum working example. Paste the below in an org buffer.


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


Now with the point anywhere in the table, when I hit "C-c *" or M-x
org-table-recalculate, I expect the first column to be auto-populated with
numbers 1,2,3,4 (or that's how I understood from the tutorial in the FAQ
link above).

But it does not work that way. Instead I need to go to each row and hit C-c
*.

So I am definitely missing out on something that's preventing the whole
table to be recalculated in one go. Any help?

Thanks!

Org-mode version 8.3.3 (release_8.3.3-597-gcaf66e @
/home/kmodi/usr_local/apps/6/emacs/emacs-25/share/emacs/site-lisp/org/)


--
Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 1961 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org table with auto-incrementing numbers in a column
  2016-02-16  4:36 org table with auto-incrementing numbers in a column Kaushal Modi
@ 2016-02-16  6:22 ` Derek Feichtinger
  2016-02-16  7:24   ` H. Dieter Wilhelm
  2016-02-16  9:58   ` Eric S Fraga
  0 siblings, 2 replies; 7+ messages in thread
From: Derek Feichtinger @ 2016-02-16  6:22 UTC (permalink / raw)
  To: emacs-orgmode

Hi

Kaushal Modi <kaushal.modi <at> gmail.com> writes:

> 
> Hi,
> I am trying to get auto-incrementing numbers in the first column in an org
table. The goal is to recalculate the numbers after adding/removing rows.
> 
> I checked out the org
FAQ: http://orgmode.org/worg/org-faq.html#fill-table-column-with-incremental-numbers
> 
> 
> But I am still not getting it to work as I need to.
> 
> Below is the minimum working example. Paste the below in an org buffer.
> 
> 
> 
> | N |   |
> |---+---|
> |   |   |
> |   |   |
> |   |   |
> |   |   |
> #+TBLFM: $1= <at> -1+1:: <at> 2$1=1
> 
> 

Try this

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


One problem is that $1 also includes the first row with the "N" heading.
that is why in your example the second and third lines both will at first
contain 1 (at least with my org version 8.3.3), and in the second iteration
only show the correct series.

> Now with the point anywhere in the table, when I hit "C-c *" or M-x
org-table-recalculate, I expect the first column to be auto-populated with
numbers 1,2,3,4 (or that's how I understood from the tutorial in the FAQ
link above).
> 
> But it does not work that way. Instead I need to go to each row and hit C-c *.

Placing point on the TBLFM line and doing C-c C-c should recalculate the
whole table.


Cheers,
Derek



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org table with auto-incrementing numbers in a column
  2016-02-16  6:22 ` Derek Feichtinger
@ 2016-02-16  7:24   ` H. Dieter Wilhelm
  2016-02-16  9:16     ` Derek Feichtinger
  2016-02-16  9:58   ` Eric S Fraga
  1 sibling, 1 reply; 7+ messages in thread
From: H. Dieter Wilhelm @ 2016-02-16  7:24 UTC (permalink / raw)
  To: emacs-orgmode

>
> Try this
>
>   | N |   |
>   |---+---|
>   |   |   |
>   |   |   |
>   |   |   |
>   |   |   |
>   #+TBLFM: <at>$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).

| N     |
|-------|
|     1 |
|     2 |
|     3 |
|     4 |
|     5 |
#+TBLFM: $1=@#-1

> Placing point on the TBLFM line and doing C-c C-c should recalculate the
> whole table.

and C-u C-c C-* does it anywhere in the table.

    Dieter
-- 
Best wishes
H. Dieter Wilhelm
Kelkheim, Germany

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org table with auto-incrementing numbers in a column
  2016-02-16  7:24   ` H. Dieter Wilhelm
@ 2016-02-16  9:16     ` Derek Feichtinger
  2016-02-16 16:51       ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Derek Feichtinger @ 2016-02-16  9:16 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org table with auto-incrementing numbers in a column
  2016-02-16  6:22 ` Derek Feichtinger
  2016-02-16  7:24   ` H. Dieter Wilhelm
@ 2016-02-16  9:58   ` Eric S Fraga
  2016-02-16 16:28     ` Kaushal Modi
  1 sibling, 1 reply; 7+ messages in thread
From: Eric S Fraga @ 2016-02-16  9:58 UTC (permalink / raw)
  To: Derek Feichtinger; +Cc: emacs-orgmode

On Tuesday, 16 Feb 2016 at 06:22, Derek Feichtinger wrote:

[...]

> Placing point on the TBLFM line and doing C-c C-c should recalculate
> the whole table.

as should C-u C-c C-c anywhere in the table.
-- 
: Eric S Fraga (0xFFFCF67D), Emacs 24.5.1, Org release_8.3.2-164-g50a182

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org table with auto-incrementing numbers in a column
  2016-02-16  9:58   ` Eric S Fraga
@ 2016-02-16 16:28     ` Kaushal Modi
  0 siblings, 0 replies; 7+ messages in thread
From: Kaushal Modi @ 2016-02-16 16:28 UTC (permalink / raw)
  To: Derek Feichtinger, emacs-org list

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

Thanks everyone for replying!

I made one mistake before posting that question: I should have looked up
C-h f org-table-recalculate. And now I did :)
I should have done "C-u C-c * " when the point was in the table (I was
doing just C-c *, which evaluates only the current row).

>> Derek
> | N |   |
> |---+---|
> |   |   |
> |   |   |
> |   |   |
> |   |   |
> #+TBLFM: @3$1..@>$1=@-1 + 1::@2$1=1

Thanks Derek! That worked! btw I was a bit perplexed looking at your
solution because it showed "<at>" instead of "@" :)

> One problem is that $1 also includes the first row with the "N" heading.
> that is why in your example the second and third lines both will at first
> contain 1 (at least with my org version 8.3.3), and in the second
iteration
> only show the correct series.

I just learned that doing "C-u C-u C-c C-c" or "C-u C-u C-c *" with the
point anywhere on the table, keeps re-evaluating the whole table till the
values are stable. (NOTE that these do not work when point is on the
#+TBLFM line; the point HAS to be inside the table).

So the original example also works just fine if I use C-u C-u C-c C-c

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

>> Dieter

Thanks! Your solution works too, with C-u C-c C-c anywhere in the table.

| N |
|---|
|   |
|   |
|   |
|   |
#+TBLFM: $1=@#-1

That said, can someone please update that FAQ at
http://orgmode.org/worg/org-faq.html#fill-table-column-with-incremental-numbers
It would be great to mention C-u C-c C-c and C-u C-u C-c C-c in that
solution too.

[-- Attachment #2: Type: text/html, Size: 3759 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: org table with auto-incrementing numbers in a column
  2016-02-16  9:16     ` Derek Feichtinger
@ 2016-02-16 16:51       ` Nicolas Goaziou
  0 siblings, 0 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2016-02-16 16:51 UTC (permalink / raw)
  To: Derek Feichtinger; +Cc: emacs-orgmode

Hello,

Derek Feichtinger <dfeich@gmail.com> writes:

> 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...

Field formulas bind stronger than column formulas. 

First, all cells with an associated field formula are marked as
read-only. Then column formulas are evaluated. Eventually, fields
formulas are evaluated.

This was introduced in Org 5.01, AFAICT. Before, the "read-only" part
would not happens, i.e, fields formulas would overwrite column formulas.

I think the idea behind this is that formulas are applied to the current
state of the table, not some intermediate one, with some formulas
applied and others not.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-02-16 16:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-16  4:36 org table with auto-incrementing numbers in a column Kaushal Modi
2016-02-16  6:22 ` Derek Feichtinger
2016-02-16  7:24   ` H. Dieter Wilhelm
2016-02-16  9:16     ` Derek Feichtinger
2016-02-16 16:51       ` Nicolas Goaziou
2016-02-16  9:58   ` Eric S Fraga
2016-02-16 16:28     ` Kaushal Modi

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.