How can we count the number of words inside a heading? (excluding the properties drawer and the actual heading title)
An example:
**Answer
:PROPERTIES:
:ID: <guid>
:END:
This is some text here
What I have been able to accomplish:
(org-id-goto "guid")
(org-mark-subtree)
(count-words (region-beginning) (region-end))
What I want is only counting This is some text here
, not the entire heading, unlike what we get via the org-mark-subtree
.
Edit: Let me perhaps describe my usecase a little more. What I am using org mode in this instance is for keeping track of word-limited essays, given a prompt. So my org file looks more like this:
* DRAFTING Essay 1
** Prompt
Describe a place in 60 words
** Answer
It is very beautiful...
What I need is to count all words under the answer heading. Unable to find a way to do so, I created an ID so that I could use it to navigate, but that seems to add the overhead of the properties drawer. If I could find a way to only get the number of words, I can subtract the (in this case, fixed) number of words/characters taken by the heading and the properties drawer and get what I need.
region-beginning
andregion-end
to do what you want, you need to select that text as the region - setmark
andpoint
at the beginning and end, for instance. (3) Can you do what you want with a keyboard macro, i.e., interactively, recording your keystrokes? If so, provide those keystrokes/actions, as a recipe to show what you want done.org-mark-subtree
does set the region but it marks the whole subtree (from the headline** Answer
to the end of the buffer or the beginning of the next subtree at the same or higher level (whichever is encountered first). So the region includes the headline (** Answer
) and the properties drawer (and possibly more things like scheduling information), both (all?) of which the OP wants to exclude from the count.org-property-end-re
and subtree end.org-agenda.el
library has a mechanism to display the notes section of the subtree (with a toggle function) .... Perhaps the O.P. could use a similar mechanism to programmatically isolate and extract the data from said notes section.