Sometimes I’d like to rename the ID property of a node. Good examples: People’s full names - ‘brian_ wilson_kernighan’ looks better than a guid. Or book titles - I’d rather use ISDN for ID. The possibility of clashes isn’t too significant.
But whenever I rewrite the ID, I have to search and replace every single link to that node. I wonder if someone already has written a function to automate that?
Nice idea. I don’t know of any code that does this, but I wonder if a nice way to do this wouldn’t be the following: in the org-roam-db-autosync--try-update-on-save-h
which is an after-save-hook
, look up what the ID was for that file beforehand, and if it’s different than what’s in the file now, offer to update all references to the old ID to the new ID. If yes, open up all the referring files one at a time, replacing the old ID with the new ID and then saving and closing.
OK I couldn’t help but look a little closer. A couple layers lower, the function org-roam-db-update-file
is called, and it calls org-roam-db-clear-file
(both in org-roam-db.el
). I think you’d need to save the value in the database before deleting the row, and then introduce a loop over references to that ID updating each of those files.
Use grep
, viewing the results in a grep buffer, then enter wgrep-mode
, edit all links and then C-x s
.
If your org-roam-directory
is also a project, then you can also use projectile-replace
. Although I’d encourage you not to ascribe meaning to IDs… in practice I never actually see them (my property drawers are folded and links font-locked).