emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Get counting of items


From: Thorsten Jolitz
Subject: Re: [O] Get counting of items
Date: Tue, 01 Apr 2014 11:00:09 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Martin Gross <address@hidden> writes:

> Dear helpers,
>
> I would like to get a counting of the first level items in a buffer
> (or even better in a region).  Since I‘m not a programmer I tried
> this, which doesn‘t work:
>
> (defun org-items-counting ()
>   "Print a message with the counting of the first level outline items
> in the current buffer"
>   (interactive)
>   (save-excursion
>      (goto-char (point-min))
>      (message "Counting of first level outline items: %d"
> (count-matches "\n* "))))
>
> Probably there is a very much better approaching to this problem.
> Could please somebody help me?

This should work, although its a bit funny (you can wrap it in an
interactive command like above):

#+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 rather something like this:

#+begin_src emacs-lisp
  (with-current-buffer "my.org"
    (let ((count 0))
      (goto-char (point-min))
      (while (re-search-forward "^\\* " nil 'noerror)
        (setq count (1+ count)))
      count))
#+end_src

-- 
cheers,
Thorsten




reply via email to

[Prev in Thread] Current Thread [Next in Thread]