From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: How to compute the number of headlines under the given headline? Date: Sun, 1 Feb 2015 15:44:46 -0500 Message-ID: References: <87d25vqfqt.fsf@wmi.amu.edu.pl> <87mw4yona2.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c3ebc887bb57050e0ce8eb Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35587) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI1Nx-0008La-UW for emacs-orgmode@gnu.org; Sun, 01 Feb 2015 15:44:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YI1Nw-0006kK-RC for emacs-orgmode@gnu.org; Sun, 01 Feb 2015 15:44:49 -0500 Received: from mail-pa0-x22d.google.com ([2607:f8b0:400e:c03::22d]:63887) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YI1Nw-0006jw-JE for emacs-orgmode@gnu.org; Sun, 01 Feb 2015 15:44:48 -0500 Received: by mail-pa0-f45.google.com with SMTP id et14so73773969pad.4 for ; Sun, 01 Feb 2015 12:44:47 -0800 (PST) In-Reply-To: <87mw4yona2.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: John Kitchin , Marcin Borkowski , Org-Mode mailing list --001a11c3ebc887bb57050e0ce8eb Content-Type: text/plain; charset=UTF-8 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 wrote: > Hello, > > John Kitchin 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 > --001a11c3ebc887bb57050e0ce8eb Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Nice and compact!

John

-----------------------------------
Professor John= Kitchin=C2=A0
Doherty Hall A207F
Department of Chemical Engineering<= br>Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
=

On Sat, Jan 31, 2015 at 12:47 PM, Nicolas Go= aziou <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
>=C2=A0 =C2=A0(org-narrow-to-subtree)
>=C2=A0 =C2=A0(1- (length
>=C2=A0 =C2=A0 (org-element-map
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-element-parse-buffer)
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 'headline
>=C2=A0 =C2=A0 =C2=A0 (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<= br> > count.

Note that, in this case,

=C2=A0 (org-element-parse-buffer 'headline)

is much more efficient.


Regards,

--
Nicolas Goaziou

--001a11c3ebc887bb57050e0ce8eb--