I think this should do it:

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

I haven't tested it extensively, but it seems to work correctly,
counting the current node and any child nodes, but not going into
sibling nodes.  I've been thinking about doing this for a while now, so
thanks for reminding me!  :)

Oh, and it uses the dash.el library, which most Emacs users should
have...


Reply via email to