emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Adam Porter <adam@alphapapa.net>
To: emacs-orgmode@gnu.org
Subject: Re: Count words under subtrees
Date: Wed, 28 Sep 2016 18:22:43 -0500	[thread overview]
Message-ID: <87mvirfw3g.fsf@alphapapa.net> (raw)
In-Reply-To: 87zimrfwwm.fsf@alphapapa.net

Forgive the triple-posting; one of these days I'll learn to wait a bit
longer before sharing.  Anyway, this updated function will avoid
counting the words in drawers and keyword-time lines
(e.g. "SCHEDULED:").

Let me know if you find anything else it needs to handle.  Skipping
source blocks is an idea, but it would be more complex.  This is
probably good enough for most uses.  :)

#+BEGIN_SRC elisp
  (defun org-count-words-in-subtree ()
    "Count words in current node and child nodes, excluding heading
  text."
    (interactive)
    (save-excursion
      (save-restriction
        (widen)
        (message "%s words in subtree"
                 (-sum (org-map-entries (lambda ()
                                          (outline-back-to-heading)
                                          (forward-line 1)
                                          (while (or (looking-at org-keyword-time-regexp)
                                                     (org-in-drawer-p))
                                            (forward-line 1))
                                          (count-words (point)
                                                       (progn
                                                         (outline-end-of-subtree)
                                                         (point))))
                                        nil 'tree))))))
#+END_SRC

  reply	other threads:[~2016-09-28 23:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27  9:01 Count words under subtrees Giacomo M
2016-09-27 18:52 ` Thorsten Jolitz
2016-09-28 22:54 ` Adam Porter
2016-09-28 23:05   ` Adam Porter
2016-09-28 23:22     ` Adam Porter [this message]
     [not found] <13cda52050fc411c8b0b7a74bd60f5c0@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2016-09-27  9:15 ` Eric S Fraga
2016-09-27  9:18 ` Eric S Fraga

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=87mvirfw3g.fsf@alphapapa.net \
    --to=adam@alphapapa.net \
    --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).