From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: Re: Count words under subtrees Date: Wed, 28 Sep 2016 17:54:57 -0500 Message-ID: <874m4zhby6.fsf@alphapapa.net> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40264) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpNlN-0005K6-Qd for emacs-orgmode@gnu.org; Wed, 28 Sep 2016 18:55:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bpNlJ-0005Lp-IZ for emacs-orgmode@gnu.org; Wed, 28 Sep 2016 18:55:40 -0400 Received: from [195.159.176.226] (port=33033 helo=blaine.gmane.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bpNlJ-0005Kw-Cb for emacs-orgmode@gnu.org; Wed, 28 Sep 2016 18:55:37 -0400 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1bpNl8-0007rD-8C for emacs-orgmode@gnu.org; Thu, 29 Sep 2016 00:55:26 +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 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...