Those who watch my Orgmode tutorial videos know that I got the habit to create a daily plan every day with links to my org files where the tasks are defined in detail. So far I created a small function that copies the ID property an item to the copy buffer, so that I can paste it to my daily plans. But this is still a lot of manual work. So I looked for improvements.
Today I hacked a bit with Emacs Lisp and added some lines to my function. The first goal was that I can press my hotkey „F5“ also in the agenda buffer, because I realized that I always press F5 there and then get the wrong IDs in my daily plans, because it then didn’t add anything to the copy buffer.
The next idea was to construct a full link, its of no use to paste just the ID into a link. So I added some more lines and constructed a complete link with an ID target and as a text I use the headline of the item. The Lisp code looks like that:
(defun my/copy-idlink-to-clipboard() "Copy an ID link with the
headline to killring, if no ID is there then create a new unique
ID. This function works only in org-mode or org-agenda buffers.
The purpose of this function is to easily construct id:-links to
org-mode items. If its assigned to a key it saves you marking the
text and copying to the killring."
(when (eq major-mode 'org-agenda-mode) ;switch to orgmode
(when (eq major-mode 'org-mode) ; do this only in org-mode buffers
(setq mytmphead (nth 4 (org-heading-components)))
(setq mytmpid (funcall 'org-id-get-create))
(setq mytmplink (format "[[id:%s][%s]]" mytmpid mytmphead))
(message "Copied %s to killring (clipboard)" mytmplink)
(global-set-key (kbd "<f5>") 'my/copy-idlink-to-clipboard)
With this hack creating links in my daily plans is fast and easy.