emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] How to compute the number of headlines under the given headline?


From: John Kitchin
Subject: Re: [O] How to compute the number of headlines under the given headline?
Date: Sat, 31 Jan 2015 09:37:34 -0500

What about:

* Count headlines in current level


#+BEGIN_SRC emacs-lisp
(save-restriction
  (org-narrow-to-subtree)
  (1- (length
   (org-element-map
       (org-element-parse-buffer)
       'headline
     (lambda (x) 1)))))
#+END_SRC

#+RESULTS:
: 5

** one
** two
*** three
**** four
** five


This counts the headline you are in, so I subtract one from the total
count.


Marcin Borkowski writes:

> Hello,
>
> I'd like to count the number of children (alternatively, number of all
> descendants) of an Org headline.  Is there a ready-made function for
> that?  If not, would using org-forward-heading-same-level and similar
> functions in Lisp code be a good idea?
>
> TIA,

--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu



reply via email to

[Prev in Thread] Current Thread [Next in Thread]