From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: emacs-orgmode@gnu.org
Subject: Re: Get counting of items
Date: Tue, 01 Apr 2014 15:55:30 -0700 [thread overview]
Message-ID: <877g78mzh9.fsf@berkeley.edu> (raw)
In-Reply-To: 87txadmnl2.fsf@gmail.com
Thorsten Jolitz <tjolitz@gmail.com> writes:
> #+begin_src emacs-lisp
> (with-current-buffer "my.org"
> (eval (append (list '+)
> (org-map-entries
> (lambda () (if (eq (org-outline-level) 1) 1 0))))))
> #+end_src
Or, slightly more simply:
#+begin_src emacs-lisp
(with-current-buffer "my.org"
(apply '+ (org-map-entries
(lambda () (if (eq (org-outline-level) 1) 1 0)))))
#+end_src
which you could wrap into a function like:
#+begin_src emacs-lisp
(defun count-toplevel-headlines ()
"Count the top level headlines in the current buffer"
(interactive)
(message
(format "Number of first level headlines: %s"
(save-excursion
(apply '+ (org-map-entries
(lambda () (if (eq (org-outline-level) 1) 1 0))))))))
#+end_src
Best,
Richard
(If possible, please encrypt your reply to me using my PGP key:
Key ID: CF6FA646
Fingerprint: 9969 43E1 CF6F A646.
See http://www.ocf.berkeley.edu/~rwl/encryption.html for more information.)
next prev parent reply other threads:[~2014-04-03 13:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-01 8:20 Get counting of items Martin Gross
2014-04-01 9:00 ` Thorsten Jolitz
2014-04-01 22:55 ` Richard Lawrence [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-04-03 8:39 Martin Gross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=877g78mzh9.fsf@berkeley.edu \
--to=richard.lawrence@berkeley.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.