4

With this:

* Cookie counter [0/2]
- [ ] Item 1
- [ ] Item 2

I can count the number of list items or TODO items.

But what if I just want to count the number of subheadings? Is it possible to get something like this:

* Cookie counter [2]
** Item 1
** Item 2

So, I wrote a function as follows:

  (defun my-no-of-headings ()
    (interactive)
    (save-excursion
      (length (org-map-entries t t 'tree))))

But when I execute it at the beginning of the heading, it does not display the number of subheadings.

What do I do to actually see the number of headings?

4
  • 1
    You can count them easily with org-map-entries and display the counts using an overlay (but org-mode uses overlays for its own purposes, so there might be conflicts).
    – NickD
    Commented Jul 2, 2019 at 12:30
  • @NickD Thanks. And sorry if it is noob question. I read up about org-map-entries in help but I am not able to grasp its use. Could you please expand your answer to include the specific way I need to use it? Will I need to write my own function that will use org-map-entries?
    – deshmukh
    Commented Jul 4, 2019 at 12:24
  • @NickD I have edited the question with an attempt that does not produce the desired result. :(
    – deshmukh
    Commented Jul 4, 2019 at 12:33
  • The function seems OK as far as it goes (although it does not need to be interactive and I'm not sure it needs the save-excursion): it returns the length of the list of entries that match (so that can be adjusted to do the "right" thing if you find that your count includes too many entries). The next step is to incorporate it into a function that sets the overlay: I don't have the time to do the research - but you can do that as well as I.
    – NickD
    Commented Jul 6, 2019 at 16:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.