emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to compute the number of headlines under the given headline?
@ 2015-01-31 12:47 Marcin Borkowski
  2015-01-31 14:37 ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: Marcin Borkowski @ 2015-01-31 12:47 UTC (permalink / raw)
  To: Org-Mode mailing list

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,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to compute the number of headlines under the given headline?
  2015-01-31 12:47 How to compute the number of headlines under the given headline? Marcin Borkowski
@ 2015-01-31 14:37 ` John Kitchin
  2015-01-31 17:47   ` Nicolas Goaziou
  0 siblings, 1 reply; 4+ messages in thread
From: John Kitchin @ 2015-01-31 14:37 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Org-Mode mailing list

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to compute the number of headlines under the given headline?
  2015-01-31 14:37 ` John Kitchin
@ 2015-01-31 17:47   ` Nicolas Goaziou
  2015-02-01 20:44     ` John Kitchin
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Goaziou @ 2015-01-31 17:47 UTC (permalink / raw)
  To: John Kitchin; +Cc: Org-Mode mailing list, Marcin Borkowski

Hello,

John Kitchin <jkitchin@andrew.cmu.edu> writes:

> 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.

Note that, in this case, 

  (org-element-parse-buffer 'headline)

is much more efficient.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: How to compute the number of headlines under the given headline?
  2015-01-31 17:47   ` Nicolas Goaziou
@ 2015-02-01 20:44     ` John Kitchin
  0 siblings, 0 replies; 4+ messages in thread
From: John Kitchin @ 2015-02-01 20:44 UTC (permalink / raw)
  To: John Kitchin, Marcin Borkowski, Org-Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 1010 bytes --]

Nice and compact!

John

-----------------------------------
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


On Sat, Jan 31, 2015 at 12:47 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> John Kitchin <jkitchin@andrew.cmu.edu> writes:
>
> > 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.
>
> Note that, in this case,
>
>   (org-element-parse-buffer 'headline)
>
> is much more efficient.
>
>
> Regards,
>
> --
> Nicolas Goaziou
>

[-- Attachment #2: Type: text/html, Size: 1892 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-01 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-31 12:47 How to compute the number of headlines under the given headline? Marcin Borkowski
2015-01-31 14:37 ` John Kitchin
2015-01-31 17:47   ` Nicolas Goaziou
2015-02-01 20:44     ` John Kitchin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).