Simon Guest writes: > At Fri, 29 Apr 2011 10:56:51 -0400, > Nick Dokos wrote: >> Indeed: it would require a bit of refactoring of Simon's code to provide the >> function(s) to apply to each entry, and changes to the top level functions to >> use the mapping API instead of looping explicitly. > > That sounds like a good idea. I may at some stage want to exclude > counting certain trees, and then I may have another look at this if > someone else hasn't already done it. > > But for now, time pressure dictates I stop hacking on my word count > function. > > cheers, > Simon I'm afraid this is a bit of a two-steps-forward, one-step-back situation, but I've rejiggered Simon's code so that it now: 1. Uses the mapping and property APIs 2. Allows selection of subtrees for count via a tag 3. Sets wordcount totals for each subtree as a property, instead of an overlay First of all, this requires the fix to =org-end-of-meta-data-and-drawers= that I sent (and then re-sent) to this list earlier today. Otherwise it will "work funny". I changed it to use properties instead of overlays because I wanted something that was persistent, and available for programmatic manipulation. Plus, you can get an overlay effect with column view. So right now M-x org-word-count will do the following: 1. Add the subtree word count as a property (=org-wc-prop-name=) to each headline in the buffer 2. Respect the region, if it's active 3. Operate only on trees tagged with =org-wc-include-tag=, if that tag is present 4. Report a buffer/region word count total in the minibuffer 5. With a prefix arg, *only* give a minibuffer report, don't set properties The two variables =org-wc-include-tag= and =org-wc-prop-name= are buffer local, unless I've misunderstood how buffer local works and screwed it up. There's a helper function, =org-wc-remove-all-props= that can be used to remove the =org-wc-prop-name= property from all headlines. Does anyone else think that =org-entry-delete= should remove the whole drawer if there are no other properties left? This is very much a proposal, and I've got a bit of time to work on it, so I'm willing to field requests, though my elisp is bad. Two immediate possibilities would be: automatically excluding subtrees tagged "noexport", and using =org-context= to be cleverer about what to avoid. Further suggestions (and code fixes) welcome! Eric