From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thorsten Jolitz Subject: Re: Get counting of items Date: Tue, 01 Apr 2014 11:00:09 +0200 Message-ID: <87txadmnl2.fsf@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:37349) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUuXK-0003is-Ap for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 04:59:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUuXD-0008LC-8l for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 04:59:14 -0400 Received: from plane.gmane.org ([80.91.229.3]:40315) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUuXD-0008L3-28 for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 04:59:07 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WUuX9-0007jU-TB for emacs-orgmode@gnu.org; Tue, 01 Apr 2014 10:59:03 +0200 Received: from e178190017.adsl.alicedsl.de ([85.178.190.17]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Apr 2014 10:59:03 +0200 Received: from tjolitz by e178190017.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 01 Apr 2014 10:59:03 +0200 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: emacs-orgmode@gnu.org Martin Gross 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