emacs-orgmode
[Top][All Lists]
Advanced

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

Re: [O] Get total number of items


From: Thorsten Jolitz
Subject: Re: [O] Get total number of items
Date: Sun, 22 Jun 2014 09:59:45 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Chris Henderson <address@hidden> writes:

> Is there a way to get the total number of items at the parent level? I
> have lots of ** under a * and I'd like to see the number at a glance.

that was asked before, here is what I came up with [using (apply '+ ...)
instead of (eval (append (list '+ ...) ...)) would even be better]:

> Here is a generalised form:
>
> #+begin_src emacs-lisp
>   (defun count-org-items (&optional level operator match scope skip)
>     "Print a counting of outline items."
>     (interactive)
>     (let ((headline-level (or level 1)) ; 1-8
>           (op (or operator '=))) ; '>= '<= '> '<
>     (save-excursion
>       (message "Counting of level%s%d outline items (match=%s, scope=%s, 
> skip=%s): %d"
>                op headline-level match scope skip
>                (eval (append (list '+)
>                              (org-map-entries
>                               `(lambda () (if (,op (org-outline-level) 
> ,headline-level) 1 0))
>                               match scope skip)))))))
> #+end_src
>
> usage:
>
> ,----------------------------------------
> | (count-org-items 2 '<= "WAITING" 'file)
> `----------------------------------------
>
> result:
>
> ,------------------------------------------------------------------------------
> | "Counting of level<=2 outline items (match=WAITING, scope=file,
> | skip=nil): 3"
> `------------------------------------------------------------------------------
>
> see C-h f org-map-entries for more info, its very powerful. Use it
> with M-: (count-org-items ...) or write a more sophisticated
> (interactive) spec.

-- 
cheers,
Thorsten




reply via email to

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