Unfortunately, org-insert-link
(C-c C-l) on an existing link does not use org-stored-links
, as you can see in its source:
;; Answers note: code taken from `org-insert-link' on commit ff8683aa35
...
(cond
(link-location) ; specified by arg, just use it.
((org-in-regexp org-link-bracket-re 1)
;; We do have a link at point, and we are going to edit it.
(setq remove (list (match-beginning 0) (match-end 0)))
(setq desc (when (match-end 2) (match-string-no-properties 2)))
(setq link (read-string "Link: "
(org-link-unescape
(match-string-no-properties 1)))))
...
Instead org-insert-link
only uses read-string
with your current link. However, we can use an advice to modify both org-stored-links
as well as the current link:
(defun remove-link-and-mark-description (&rest args)
"Removes the link at point and marks the description.
The previous link gets stored into `org-stored-links'. ARGS is unused"
(cond
((org-in-regexp org-link-bracket-re 1)
(let* ((link (match-string-no-properties 1))
(desc (if (match-end 2) (match-string-no-properties 2) link))
(deactivate-mark))
(push (list (org-link-unescape link) desc) org-stored-links)
(replace-match desc)
(push-mark (match-beginning 0) t t)))
(t nil)))
(advice-add 'org-insert-link :before #'remove-link-and-mark-description)
However, the code above is merely a proof of concept. There are some bugs, e.g. the stored link doesn't follow Org's usual file:...
format if used on files, and push
should probably get replaced by add-to-list
.