Re: [O] org table with auto-incrementing numbers in a column
Hello, Derek Feichtingerwrites: > 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 2$1) > > | N | | > |---+---| > | | | > | 1 | | > | 2 | | > | 3 | | > #+TBLFM: $1= -1 + 1:: 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
Re: [O] org table with auto-incrementing numbers in a column
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 "" 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.
Re: [O] org table with auto-incrementing numbers in a column
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
Re: [O] org table with auto-incrementing numbers in a column
Hi > > > > Try this > > > > | N | | > > |---+---| > > | | | > > | | | > > | | | > > | | | > > #+TBLFM: $1..>$1= -1 + 1:: 2$1=1 > > Sorry, I had a typo from copying and replacing in my formula should be | N | | |---+---| | 1 | | | 2 | | | 3 | | | 4 | | #+TBLFM: 3$1..>$1= -1 + 1:: 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 2$1) | N | | |---+---| | | | | 1 | | | 2 | | | 3 | | #+TBLFM: $1= -1 + 1:: 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= #-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
Re: [O] org table with auto-incrementing numbers in a column
> > Try this > > | N | | > |---+---| > | | | > | | | > | | | > | | | > #+TBLFM: $1..>$1= -1 + 1:: 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
Re: [O] org table with auto-incrementing numbers in a column
Hi Kaushal Modi 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= -1+1:: 2$1=1 > > Try this | N | | |---+---| | | | | | | | | | | | | #+TBLFM: $1..>$1= -1 + 1:: 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