I have a document full of internal org-mode links of the form:
* Target Heading
...
[[Target Heading][Description]]
However, these break whenever I edit the heading that they link to, so I want to replace them with links of the form:
* Target Heading
:PROPERTIES:
:ID: 403847B2-3D4C-4EFB-96DE-E0C5C52A02B5
:END:
...
[[#403847B2-3D4C-4EFB-96DE-E0C5C52A02B5][Description]]
I have started on some code that will follow the link at point, add an id to the heading it finds and save the link to that heading. I then want to update the link with the new target:
(defun adam-open ()
(require 'org-id)
(save-excursion
(save-restriction
(call-interactively 'org-open-at-point)
(call-interactively 'org-store-link)))
(org-insert-link))
The trouble with this is that because the link under point already points to a text-based link, org-insert-link
fails to replace the target with the stored id. Also, org-insert-link
works interactively
Is there any way to pass the id as a parameter to org-insert-link
so that it overrides the default text-based target and avoids the interactive prompt?