This is the code for the OrgMode tutorial E05S02 video. I tried to put the elisp code for the Emacs initialization into the YouTube description, but I saw a note, that parenthesis is not allowed in the description. Ok, then I put it here and here we go:
The first code snippet is something I found on StackOverflow.
(defun my/org-add-ids-to-headlines-in-file ()
"Add ID properties to all headlines in the current file which
do not already have one."
(add-hook 'before-save-hook 'my/org-add-ids-to-headlines-in-file nil 'local)))
The purpose of this code is that it creates ID properties for every headline (if there isn’t one already) when you save your OrgMode file.
The next code snipped was made by myself. I have not much experience in Elisp programming, but Google turned out to be helpful and so I made this piece of code:
(defun my/copy-id-to-clipboard() "Copy the ID property value to killring,
if no ID is there then create a new unique ID.
This function works only in org-mode 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-mode) ; do this only in org-mode buffers
(setq mytmpid (funcall 'org-id-get-create))
(message "Copied %s to killring (clipboard)" mytmpid)
(global-set-key (kbd "<f5>") 'my/copy-id-to-clipboard)
This function is bound to the F5 key. Whenever you press F5 then it takes the ID and copies it to the killring (aka Clipboard). If the headline has no ID property it creates one. In that way, you can easily create links to IDs because copying the ID is just one keystroke.