tsarcasmic · 2022-10-03 19:25
I found how to grow an integer here:
https://emacs.stackexchange.com/questions/14681/org-mode-table-row-number-grow-automatically
| | title |
|---+-------|
| 1 | |
| 2 | |
| 3 | |
#+tblfm: $1=@#-1
This works really well, now I can add or remove rows and c-c c-c the formula to get the numbers back in order.
But I want to do the same for dates. I can write functions (in/decremement date), but I don't understand how I would hook them up to the tblfm thing... Any suggestions?
Thanks for reading.
ffellirm · 2022-10-05 02:16
One of the following methods might work for you, without writing elisp
and hooking it up to the "#+tblfm:" line.
If you want to have the reference date in the second row of the table itself:
| | title |
|------------------+-------|
| [2022-10-05 Wed] | |
| [2022-10-06 Thu] | |
| [2022-10-07 Fri] | |
#+tblfm: @3$1..@>$1=@-1 + 1
If you want to have the reference date in the "#+tblfm:" row:
| | title |
|------------------+-------|
| [2022-10-05 Wed] | |
| [2022-10-06 Thu] | |
| [2022-10-07 Fri] | |
#+tblfm: @2$1=[2022-10-05 Wed]::@3$1..@>$1=@-1 + 1
or this:
| | title |
|------------------+-------|
| [2022-10-05 Wed] | |
| [2022-10-06 Thu] | |
| [2022-10-07 Fri] | |
#+tblfm: @2$1..@>$1=[2022-10-05 Wed] + @# - 2
If you want to have a reference time in the second row of the table itself:
| | title |
|------------------------+-------|
| [2022-10-05 Wed 09:00] | |
| [2022-10-05 Wed 10:00] | |
| [2022-10-05 Wed 11:00] | |
#+tblfm: @3$1..@>$1=@-1 + 1/24
If you want to have a reference time in the "#+tblfm:" row:
| | title |
|------------------------+-------|
| [2022-10-05 Wed 09:00] | |
| [2022-10-05 Wed 10:00] | |
| [2022-10-05 Wed 11:00] | |
#+tblfm: @2$1=[2022-10-05 Wed 09:00]::@3$1..@>$1=@-1 + 1/24
or this:
| | title |
|------------------------+-------|
| [2022-10-05 Wed 09:00] | |
| [2022-10-05 Wed 10:00] | |
| [2022-10-05 Wed 11:00] | |
#+tblfm: @2$1..@>$1=[2022-10-05 Wed 09:00] + (@# - 2)/24
If those don't do what you want, and you have some particular elisp you want to use in the table
you could hook it up to the "#+tblfm:" line as described in
[3.5.3 Emacs Lisp forms as formulas](https://www.gnu.org/software/emacs/manual/html_node/org/Formula-syntax-for-Lisp.html)
tsarcasmic · 2022-10-05 04:59
Incredibly helpful, thank you for sharing your knowledge. The first one does what I want, the other options are even better!