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.
1 2 3 4 5 6 7 8 9 |
(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." (interactive) (org-map-entries 'org-id-get-create)) (add-hook 'org-mode-hook (lambda () (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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
(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." (interactive) (when (eq major-mode 'org-mode) ; do this only in org-mode buffers (setq mytmpid (funcall 'org-id-get-create)) (kill-new mytmpid) (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.
[ratings ]
Pingback: OrgMode tutorial episode 5 | König von Haunstetten
Much thanks for this, and for the idea itself. FWIW, I initially tried your tip with both pieces of code. But in practice, I don’t need all those properties and IDs for every item in my org life. But the way you have it, I can use only the second piece of code, and that generates the IDs on demand when needed. For my use, that’s perfect. Danke, Rainer