Org-mode, a practical example

Last org-mode article for now, I promise.

Let's say you're planning a birthday party. We'll start with a checklist.

- [/] Plan party
  - [ ] Invite friends
  - [ ] Buy snacks
  - [ ] Bake cake

You can tick off each entry by holding Ctrl and pressing C twice while the line is active. Now let's start budgeting.

#+NAME: Budget
| Category      | Budget (£) | Spent (£) |
|---------------+------------+-----------|
| Snacks        |         20 |         0 |
| Cake          |         10 |         0 |
| Entertainment |         10 |         0 |
|---------------+------------+-----------|
| Total         |            |           |

Add the formulas for the two columns next to “Total” by typing “:=vsum(@I..II) and Org-mode will store them underneath the table like so:

#+TBLFM: @5$2=vsum(@I..II)::@5$3=vsum(@I..II)

Quick tip, change @5 to @>. That way you're referring to the last row, not the 5th. It only matters if you want to add more rows to the table, but it's worth doing anyway.

Now we need tables for each category.

#+NAME: Snacks
| Item    | Budget |
|---------+--------|
| Crisps  |      7 |
| Pizza   |      6 |
| Popcorn |      5 |
|---------+--------|
| Total   |     18 |
#+TBLFM: @>$2=vsum(@I..II)

#+NAME: Cake
| Item      | Budget |
|-----------+--------|
| Cake Mix  |      2 |
| Milk      |      1 |
| Eggs      |   1.80 |
| Chocolate |      1 |
|-----------+--------|
| Total     |    5.8 |
#+TBLFM: @>$2=vsum(@I..II)

#+NAME: Entertainment
| Item            | Budget |
|-----------------+--------|
| Cheap movie DVD |      6 |
|-----------------+--------|
| Total           |      6 |
#+TBLFM: @>$2=vsum(@I..II)

Now we reveal the purpose of the #+NAME tag. We can call fields from different tables using it. Going back to the first table, replace the spent field of each item with “:=remote(name, coordinate)”

#+NAME: Budget
| Category      | Budget (£) | Spent (£) |
|---------------+------------+-----------|
| Snacks        |         20 |        18 |
| Cake          |         10 |       5.8 |
| Entertainment |         10 |         6 |
|---------------+------------+-----------|
| Total         |         40 |      29.8 |
#+TBLFM: @>$2=vsum(@I..II)::@>$3=vsum(@I..II)::@2$3=remote(Snacks, @>$2)::@3$3=remote(Cake, @>$2)::@4$3=remote(Entertainment, @>$2)

And we're done! A checklist to keep track of progress, and a table managing budgets. The only thing to add here is a recalculate button, so you don't have to keep hitting C-c, C-c every time. Add this above the tables: [[elisp:(org-table-iterate-buffer-tables)][Recalculate]] This uses the link feature touched upon earlier to call a function that repeatedly calculates every table in the buffer until nothing changes, all at the click of a button.

With these articles I've only barely scratched the surface of what Org-mode is capable of. It supports embedding code blocks of multiple different languages and having each one inter-operate, it has a calendar system with agenda, and has a feature called “capture” to automatically save random notes to a specified file for easy access. Every time I look at Org-mode, and Emacs as a whole, I learn something new that I never noticed before.