emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Count words under subtrees


From: Adam Porter
Subject: Re: [O] Count words under subtrees
Date: Wed, 28 Sep 2016 18:22:43 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

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

[Prev in Thread] Current Thread [Next in Thread]