Thorsten Jolitz <tjol...@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.)


Reply via email to