From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: Re: Count words under subtrees Date: Wed, 28 Sep 2016 18:22:43 -0500 Message-ID: <87mvirfw3g.fsf@alphapapa.net> References: <874m4zhby6.fsf@alphapapa.net> <87zimrfwwm.fsf@alphapapa.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:45654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpOCI-0005RQ-3d for emacs-orgmode@gnu.org; Wed, 28 Sep 2016 19:23:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpOCC-0004L4-Kp for emacs-orgmode@gnu.org; Wed, 28 Sep 2016 19:23:30 -0400 Received: from [195.159.176.226] (port=41528 helo=blaine.gmane.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpOCC-0004Jd-DZ for emacs-orgmode@gnu.org; Wed, 28 Sep 2016 19:23:24 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1bpOBp-0000j5-Rl for emacs-orgmode@gnu.org; Thu, 29 Sep 2016 01:23:01 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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