emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Re: Get counting of items
@ 2014-04-03  8:39 Martin Gross
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Gross @ 2014-04-03  8:39 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Dear Thorsten

> 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 v org-map-entries for more info, its very powerfull. Use it
> with M-: (count-org-items ...) or write a more sophisticated
> (interactive) spec.
>

Very impressive. Thank you very much!

Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread
* Get counting of items
@ 2014-04-01  8:20 Martin Gross
  2014-04-01  9:00 ` Thorsten Jolitz
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Gross @ 2014-04-01  8:20 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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?

Thanks in advance,

Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-04-03 13:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-03  8:39 Get counting of items Martin Gross
  -- strict thread matches above, loose matches on Subject: below --
2014-04-01  8:20 Martin Gross
2014-04-01  9:00 ` Thorsten Jolitz
2014-04-01 22:55   ` Richard Lawrence

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).