[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Get counting of items
From: |
Richard Lawrence |
Subject: |
Re: [O] Get counting of items |
Date: |
Tue, 01 Apr 2014 15:55:30 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
Thorsten Jolitz <address@hidden> 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.)