* Jean Louis <bugs@gnu.support> [2025-04-14 14:20]: > Is there any existing function in the org mode API which would give > me all the org headings of a single file in a list? > > In particular, I would like to get the heading title separate with > the content in a cons. > > For example > > org-heading-list => '(("* Heading #1" "My text #1") ("* Heading #2") ("My > text 2")) > > It is going to become very useful because many people are linking to > headings how I know is it true that many people in org mode, many org > mode users wish to link to headings?
(defun rcd-org-get-headings-with-contents () "Return a list of all Org headings with their contents. Each element is a plist with :heading (title), :level, and :contents (text)." (let ((tree (org-element-parse-buffer 'headline))) (org-element-map tree 'headline (lambda (hl) (let* ((beg (org-element-property :begin hl)) (end (org-element-property :end hl)) (contents (buffer-substring-no-properties (org-element-property :contents-begin hl) (org-element-property :contents-end hl)))) (list :level (org-element-property :level hl) :heading (org-element-property :raw-value hl) :contents contents :begin beg :end end)))))) Now I have found, um, I have found solution to this problem. -- Jean Louis