reddit / emacs

How to calculate a cell in org-table ONLY if it isn't populated?

m518xt · 2022-09-01 06:55
I need to add a UUID to each row in a table, but I also need to keep any existing IDs without changing them. It's simple enough to add a UUID with `'(org-id-new)`: | Col1 | UUID | |-------+--------------------------------------| | test1 | 1BFBFCAA-CD59-4D4E-9956-CA27B3DCED1E | | test2 | 18209466-723B-4820-A175-0237769548FD | #+TBLFM: $2='(org-id-new) Going forward I want to **keep** those UUIDs and only generate new ones for new rows. I thought I could try `'(unless $2 (org-id-new)), but` I get `nil`s. Is there a reference for the current cell, or a way to only apply a calculation to an empty cell?
m518xt · 2022-09-01 09:33
Thinking about it helped me realise the solution. The `unless` is returning `nil` (as it should), so the correct form is: `'(if (string-empty-p $2) (org-id-new) $2)` ...where `(string-empty-p $2)` as the test for an empty cell comes from [this answer](https://www.reddit.com/r/orgmode/comments/e51oag/comment/f9io5fq/?utm_source=share&utm_medium=web2x&context=3) to a question that I didn't see when I was searching.
[deleted] · 2022-09-01 09:45
[deleted]