that is often true, especially with large buffers, but you have to add a
bunch of code to go to point-max, and check the level with this.
#+BEGIN_SRC emacs-lisp
(save-excursion
(goto-char (point-max))
(let (components
(headings '()))
(while (re-search-backward org-complex-heading-regexp nil t)
(setq components (org-heading-components))
(when (= (first components) 1)
(push (fifth components) headings)))
headings))
#+END_SRC
This takes about 0.04 ms on a small example. The org-map-entries approach
takes 0.6ms on the same example. In a big buffer that might be noticeable!
John
-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
On Wed, May 19, 2021 at 10:19 AM Jonathan Gregory <[email protected]>
wrote:
> Hi
>
> On 19 May 2021, John Kitchin wrote:
>
> > I think this is all you need to get a list of titles of level 1
> > headings as strings
> >
> > (org-map-entries (lambda () (fifth (org-heading-components)))
> > "LEVEL=1")
> >
> > this also works for me:
> >
> > #+BEGIN_SRC emacs-lisp
> > (org-map-entries (lambda () (org-element-property :title
> > (org-element-at-point)) ) "LEVEL=1")
> > #+END_SRC
>
> This is a better approach indeed. No need to create a new list,
> although I get faster results using:
>
> (while (re-search-backward org-complex-heading-regexp nil t)
>
>
> --
> Jonathan
>
>