I want to apply (org-id-get-create) to every top-level heading in the buffer. How can I loop through all top-level org-mode headings in the current buffer?


You can use org-map-entries to apply a function to all the entries in a org-mode buffer matching a search. In this case the search "LEVEL=1" will match all top level headlines. The function you specify will be called without arguments with the point on the headline. So (org-map-entries 'org-id-get-create "LEVEL=1") will apply the org-id-get-create function to every LEVEL 1 headline.

| improve this answer | |

I couldn't find an built-in org function for that, the following function should solve it.

(defun adl/org-top-level-heading-cycle ()
  (if (not (search-forward-regexp "^* " nil t))
    (goto-char 1)
    (search-forward-regexp "^* " nil t))))
| improve this answer | |

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.