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 via email to