From: Thorsten Jolitz <tjolitz@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Get counting of items
Date: Tue, 01 Apr 2014 11:00:09 +0200 [thread overview]
Message-ID: <87txadmnl2.fsf@gmail.com> (raw)
In-Reply-To: CAJkULmnCfqE9ODEQZ=4FmUG6-XXSVNkWrZ82hV-JLK1wTF5EGw@mail.gmail.com
Martin Gross <m-gross@gmx.net> 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
next prev parent reply other threads:[~2014-04-01 8:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-01 8:20 Get counting of items Martin Gross
2014-04-01 9:00 ` Thorsten Jolitz [this message]
2014-04-01 22:55 ` Richard Lawrence
-- strict thread matches above, loose matches on Subject: below --
2014-04-03 8:39 Martin Gross
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87txadmnl2.fsf@gmail.com \
--to=tjolitz@gmail.com \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).