4

I noticed I copy-paste entire headers (with content) quite often. The problem I also notice is that this creates a lot of headers with duplicate IDs. I wonder if anyone has a function he would like to share or can help me create a function that will

  1. copy current header and contents (org-copy-subtree) at point
  2. paste it below current header
  3. change ID
1

I often need to copy/paste a large tree and had the same problem with duplicate ids. Now, after pasting the tree, I narrow to the tree and run the following function. This will visit every heading at any level in the tree and either change its id or, for newly-created headings, give it an id.

(defun bw/org-add-update-ids-to-headlines-in-file ()
  "Add ID properties to all visible headlines in the current file which
do not already have one.  Change the IDs of those that already have them."
  (interactive)
  (org-map-entries '(lambda () (org-id-get-create t))))

(spacemacs/set-leader-keys "oa" 'bw/org-add-update-ids-to-headlines-in-file)

Maybe I should also look into adding an id automatically every time I create a new heading...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.