emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Counting number of children under heading
@ 2014-04-17  9:15 Marvin Doyley
  2014-04-17  9:21 ` Bastien
  2014-04-17 10:55 ` Eric Abrahamsen
  0 siblings, 2 replies; 13+ messages in thread
From: Marvin Doyley @ 2014-04-17  9:15 UTC (permalink / raw)
  To: emacs-orgmode

Hi there,

I would like to automatically count the number of children under a given heading. For example, I would like to have

* Cars (2)
** BMW
** Escort

 Putting  [/] at the end of header (in this case Cars), then putting the TODO keyword before each sub-header give me a partial solution

* Cars [/]
** TODO BMW
** TODO Escort


Is there way to do this without using the TODO keyword ?

Thanks,
M

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-17  9:15 Marvin Doyley
@ 2014-04-17  9:21 ` Bastien
  2014-04-17  9:42   ` Thorsten Jolitz
  2014-04-18 13:54   ` Sebastien Vauban
  2014-04-17 10:55 ` Eric Abrahamsen
  1 sibling, 2 replies; 13+ messages in thread
From: Bastien @ 2014-04-17  9:21 UTC (permalink / raw)
  To: Marvin Doyley; +Cc: emacs-orgmode

Hi Marvin,

Marvin Doyley <marvinpas@gmail.com> writes:

> I would like to automatically count the number of children under a
> given heading. For example, I would like to have
>
> * Cars (2)
> ** BMW
> ** Escort

There is no such feature in Org, but I seem to remember someone
hack something similar -- maybe someone else with a better memory
can tell.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-17  9:21 ` Bastien
@ 2014-04-17  9:42   ` Thorsten Jolitz
  2014-04-18 13:54   ` Sebastien Vauban
  1 sibling, 0 replies; 13+ messages in thread
From: Thorsten Jolitz @ 2014-04-17  9:42 UTC (permalink / raw)
  To: emacs-orgmode

Bastien <bzg@gnu.org> writes:

> Hi Marvin,
>
> Marvin Doyley <marvinpas@gmail.com> writes:
>
>> I would like to automatically count the number of children under a
>> given heading. For example, I would like to have
>>
>> * Cars (2)
>> ** BMW
>> ** Escort
>
> There is no such feature in Org, but I seem to remember someone
> hack something similar -- maybe someone else with a better memory
> can tell.

Not the same thing (because its about "weight" (= number of hidden
lines) when folded, but somehow related:

Org Weights (by Francois Pinard):

,--------------------------------------
| https://github.com/pinard/org-weights
`--------------------------------------

Org Hidden Line Cookies (by me):

,--------------------------------
| https://github.com/tj64/org-hlc
`--------------------------------

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-17  9:15 Marvin Doyley
  2014-04-17  9:21 ` Bastien
@ 2014-04-17 10:55 ` Eric Abrahamsen
  2014-04-17 12:02   ` Thorsten Jolitz
  1 sibling, 1 reply; 13+ messages in thread
From: Eric Abrahamsen @ 2014-04-17 10:55 UTC (permalink / raw)
  To: emacs-orgmode

Marvin Doyley <marvinpas@gmail.com> writes:

> Hi there,
>
> I would like to automatically count the number of children under a given heading. For example, I would like to have
>
> * Cars (2)
> ** BMW
> ** Escort
>
>  Putting  [/] at the end of header (in this case Cars), then putting the TODO keyword before each sub-header give me a partial solution
>
> * Cars [/]
> ** TODO BMW
> ** TODO Escort
>
>
> Is there way to do this without using the TODO keyword ?
>
> Thanks,
> M

I could have sworn someone posted a thing for this just a week or two
ago, using `org-map-entries' and the identity function, and counting the
results. Anyway look at the docstring for `org-map-entries', it takes a
SCOPE argument you can set to 'tree to just map the headings under the
current one. A stupid example might look like:

(apply '+ (org-map-entries (lambda () 1) t 'tree))

Though that will count the top-level heading, as well.

E

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-17 10:55 ` Eric Abrahamsen
@ 2014-04-17 12:02   ` Thorsten Jolitz
  2014-04-17 13:10     ` Eric Abrahamsen
  0 siblings, 1 reply; 13+ messages in thread
From: Thorsten Jolitz @ 2014-04-17 12:02 UTC (permalink / raw)
  To: emacs-orgmode

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> I could have sworn someone posted a thing for this just a week or two
> ago, using `org-map-entries' and the identity function, and counting the
> results. 

Ups, that was me  ... forgot about it ;)

#+begin_quote
From: Martin Gross <m-gross@gmx.net>
Subject: Re: Get counting of items
Newsgroups: gmane.emacs.orgmode
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Date: Thu, 3 Apr 2014 10:39:18 +0200 (2 weeks, 3 hours, 19 minutes ago)

Dear Thorsten

> Here is a generalised form:
>
> #+begin_src emacs-lisp
>   (defun count-org-items (&optional level operator match scope skip)
>     "Print a counting of outline items."
>     (interactive)
>     (let ((headline-level (or level 1)) ; 1-8
>           (op (or operator '=))) ; '>= '<= '> '<
>     (save-excursion
>       (message "Counting of level%s%d outline items (match=%s, scope=%s, skip=%s): %d"
>                op headline-level match scope skip
>                (eval (append (list '+)
>                              (org-map-entries
>                               `(lambda () (if (,op (org-outline-level) ,headline-level) 1 0))
>                               match scope skip)))))))
> #+end_src
>
> usage:
>
> ,----------------------------------------
> | (count-org-items 2 '<= "WAITING" 'file)
> `----------------------------------------
>
> result:
>
> ,------------------------------------------------------------------------------
> | "Counting of level<=2 outline items (match=WAITING, scope=file,
> | skip=nil): 3"
> `------------------------------------------------------------------------------
>
> see C-h f org-map-entries for more info, its very powerfull. Use it
> with M-: (count-org-items ...) or write a more sophisticated
> (interactive) spec.
#+end_quote

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-17 12:02   ` Thorsten Jolitz
@ 2014-04-17 13:10     ` Eric Abrahamsen
  0 siblings, 0 replies; 13+ messages in thread
From: Eric Abrahamsen @ 2014-04-17 13:10 UTC (permalink / raw)
  To: emacs-orgmode

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> I could have sworn someone posted a thing for this just a week or two
>> ago, using `org-map-entries' and the identity function, and counting the
>> results. 
>
> Ups, that was me  ... forgot about it ;)

I thought so!

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
@ 2014-04-17 13:44 Marvin Doyley
  2014-04-17 14:43 ` Thorsten Jolitz
  0 siblings, 1 reply; 13+ messages in thread
From: Marvin Doyley @ 2014-04-17 13:44 UTC (permalink / raw)
  To: tjolitz; +Cc: emacs-orgmode


Hi Thorsten,

Your hidden line cookie is what I am looking for. If I understand it I should do the following

* Fruits [# ]
** Apples
** Pears

M-x org-hlc-toggle-hidden-lines-cookies ?

When ever I do this I get the following error

Symbol’s function definition is void: outline-body visible-p, 

The backtrace is included below.

Thanks
M

Debugger entered--Lisp error: (void-function outline-body-visible-p)
  (outline-body-visible-p)
  (not (outline-body-visible-p))
  (or (not (outline-body-visible-p)) (re-search-forward org-hlc-hidden-lines-cookie-format-regexp (line-end-position) (quote NO-ERROR)))
  (progn (or (not (outline-body-visible-p)) (re-search-forward org-hlc-hidden-lines-cookie-format-regexp (line-end-position) (quote NO-ERROR))))
  (unwind-protect (progn (or (not (outline-body-visible-p)) (re-search-forward org-hlc-hidden-lines-cookie-format-regexp (line-end-position) (quote NO-ERROR)))) (set-match-data save-match-data-internal (quote evaporate)))
  (let ((save-match-data-internal (match-data))) (unwind-protect (progn (or (not (outline-body-visible-p)) (re-search-forward org-hlc-hidden-lines-cookie-format-regexp (line-end-position) (quote NO-ERROR)))) (set-match-data save-match-data-internal (quote evaporate))))
  (save-excursion (let ((save-match-data-internal (match-data))) (unwind-protect (progn (or (not (outline-body-visible-p)) (re-search-forward org-hlc-hidden-lines-cookie-format-regexp (line-end-position) (quote NO-ERROR)))) (set-match-data save-match-data-internal (quote evaporate)))))
  org-hlc-hidden-lines-cookie-status-changed-p()
  (and (outline-on-heading-p) (org-hlc-hidden-lines-cookie-status-changed-p) (org-hlc-set-hidden-lines-cookie))
  (save-excursion (goto-char (point-min)) (and (outline-on-heading-p) (org-hlc-hidden-lines-cookie-status-changed-p) (org-hlc-set-hidden-lines-cookie)) (while (not (eobp)) (outline-next-visible-heading 1) (and (outline-on-heading-p) (org-hlc-hidden-lines-cookie-status-changed-p) (org-hlc-set-hidden-lines-cookie))))
  org-hlc-write-hidden-lines-cookies()
  org-hlc-show-hidden-lines-cookies()
  (if org-hlc-hidden-lines-cookies-on-p (org-hlc-hide-hidden-lines-cookies) (org-hlc-show-hidden-lines-cookies))
  org-hlc-toggle-hidden-lines-cookies()
  call-interactively(org-hlc-toggle-hidden-lines-cookies record nil)
  command-execute(org-hlc-toggle-hidden-lines-cookies record)
  (progn (setq prefix-arg current-prefix-arg) (setq this-command chosen-item) (command-execute chosen-item (quote record)))
  (unwind-protect (progn (setq prefix-arg current-prefix-arg) (setq this-command chosen-item) (command-execute chosen-item (quote record))) (smex-rank chosen-item) (smex-show-key-advice chosen-item) (run-at-time 0.01 nil (function (lambda (cmd) (setq last-repeatable-command cmd))) chosen-item))
  (if smex-custom-action (let ((action smex-custom-action)) (setq smex-custom-action nil) (funcall action chosen-item)) (unwind-protect (progn (setq prefix-arg current-prefix-arg) (setq this-command chosen-item) (command-execute chosen-item (quote record))) (smex-rank chosen-item) (smex-show-key-advice chosen-item) (run-at-time 0.01 nil (function (lambda (cmd) (setq last-repeatable-command cmd))) chosen-item)))
  (let ((chosen-item (intern (smex-completing-read commands initial-input)))) (if smex-custom-action (let ((action smex-custom-action)) (setq smex-custom-action nil) (funcall action chosen-item)) (unwind-protect (progn (setq prefix-arg current-prefix-arg) (setq this-command chosen-item) (command-execute chosen-item (quote record))) (smex-rank chosen-item) (smex-show-key-advice chosen-item) (run-at-time 0.01 nil (function (lambda (cmd) (setq last-repeatable-command cmd))) chosen-item))))
  smex-read-and-run(("toggle-debug-on-error" "org-mode" "text-mode" "artist-mode" "color-theme-snow" "eshell" "load-file" "notes" "org-bibtex-yank" "tea-time" "brain" "insert-date" "org-bibtex-read" "org-hlc-toggle-hidden-lines-cookies" "el-get-install" "org-bibtex-search" "skimCopy" "word-count" "desktop-read" "word-count-mode" "marv:create-scratch-buffer" "matlab-shell" "el-get-list-packages" "wl" "dired" "org-insert-drawer" "text-scale-increase" "org-hlc-hide-hidden-lines-cookies" "org-export-insert-default-template" "python-mode" "desktop-save" "writegood-mode" "artbollocks-mode" "el-get-self-update" "marv:org-entry-wpm" "org-bibtex" "insert-time" "org-capture" "move-border-up" "org-mobile-pull" "org-bibtex-write" "org-bibtex-read-file" "org-habit-toggle-habits" "marv:toggle-line-spacing" "comment-or-uncomment-region" "version" "mail-mode" "reftex-toc" "bibtex-mode" "matlab-mode" ...))
  (if (smex-already-running) (smex-update-and-rerun) (and smex-auto-update (smex-detect-new-commands) (smex-update)) (smex-read-and-run smex-ido-cache))
  smex()
  call-interactively(smex nil nil)

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-17 13:44 Counting number of children under heading Marvin Doyley
@ 2014-04-17 14:43 ` Thorsten Jolitz
  0 siblings, 0 replies; 13+ messages in thread
From: Thorsten Jolitz @ 2014-04-17 14:43 UTC (permalink / raw)
  To: emacs-orgmode

Marvin Doyley <marvinpas@gmail.com> writes:

Hi Thorsten,
>
> Your hidden line cookie is what I am looking for. If I understand it I
> should do the following
>
> * Fruits [# ]
> ** Apples
> ** Pears
>
> M-x org-hlc-toggle-hidden-lines-cookies ?
>
> When ever I do this I get the following error
>
> Symbol’s function definition is void: outline-body visible-p, 
>
> The backtrace is included below.

Just tested `org-hlc-toggle-hidden-lines-cookies' with an org file:

,----------------------------------------------------
| 3 matches for "^\* " in buffer: org-outside-org.org
|      15:* Introduction [#30]
|      46:* Org-mode everywhere [#876]
|     923:* Screencasts  [#20]
`----------------------------------------------------

and

,-----------------------------------------------------------
| 12 matches for "^\*\*?\*? " in buffer: org-outside-org.org
|      15:* Introduction [#30]
|      46:* Org-mode everywhere
|      50:** File Structuring
|      54:*** orgstruct  [#39]
|      94:*** Outline with Outshine  [#186]
|     281:** Subtree and Comment Editing
|     285:*** Introduction [#18]
|     304:*** Outorg [#112]
|     417:*** Poporg [#291]
|     709:** Remote Buffer Control [#213]
|     923:* Screencasts  [#20]
`-----------------------------------------------------------

and it seems to work here ... but thats because I always load
outshine.el and therefore took this function for granted:

,------------------------------------------------------------
| outline-body-visible-p is a Lisp function in `outshine.el'.
| 
| (outline-body-visible-p)
`------------------------------------------------------------

I fixed this in master right now, so if you pull the newest version it
should work. 

Note that org-hlc.el is 'wrong' in some ways:
- it only acts when called, not via a hook or so
- it actually modifies the buffer to insert and delete the cookies

but it works more or less, even for massive files.

I tried the right way (visibility change hook and overlays) and noticed
that my user experience went downhill pretty fast in big files - seems
that Emacs display engine is overwhelmed at some point. 

PS 
Why is flyspell-mode turned on automatically in the magit commit-msg
buffer now? I did not do anything about it and don't want it anyway ...

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
@ 2014-04-17 16:21 Doyley, Marvin M.
  0 siblings, 0 replies; 13+ messages in thread
From: Doyley, Marvin M. @ 2014-04-17 16:21 UTC (permalink / raw)
  To: tjolitz@gmail.com; +Cc: emacs-orgmode@gnu.org


Hi Thorsten,

It is not working like a charm.

Thanks
M

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-17  9:21 ` Bastien
  2014-04-17  9:42   ` Thorsten Jolitz
@ 2014-04-18 13:54   ` Sebastien Vauban
  2014-04-18 14:50     ` Sacha Chua
  1 sibling, 1 reply; 13+ messages in thread
From: Sebastien Vauban @ 2014-04-18 13:54 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Bastien wrote:
> Marvin Doyley <marvinpas-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
>> I would like to automatically count the number of children under a
>> given heading. For example, I would like to have
>>
>> * Cars (2)
>> ** BMW
>> ** Escort
>
> There is no such feature in Org, but I seem to remember someone
> hack something similar -- maybe someone else with a better memory
> can tell.

IIRC, Sacha Chua had made such a hack -- must be found on her impressive
blog.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-18 13:54   ` Sebastien Vauban
@ 2014-04-18 14:50     ` Sacha Chua
  2014-04-20 17:28       ` Sebastien Vauban
  0 siblings, 1 reply; 13+ messages in thread
From: Sacha Chua @ 2014-04-18 14:50 UTC (permalink / raw)
  To: emacs-orgmode

Sebastien Vauban <sva-news@mygooglest.com>
writes:

>>> I would like to automatically count the number of children under a
>>> given heading. For example, I would like to have
>>> * Cars (2)
>>> ** BMW
>>> ** Escort
>> There is no such feature in Org, but I seem to remember someone
>> hack something similar -- maybe someone else with a better memory
>> can tell.
> IIRC, Sacha Chua had made such a hack -- must be found on her impressive
> blog.

I don't remember doing something like that - I tend to use [X] for
automatically counted cookies...

Do you need the number of children to be part of the text, or is it okay
for that to be temporarily displayed? 

Sacha

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-18 14:50     ` Sacha Chua
@ 2014-04-20 17:28       ` Sebastien Vauban
  2014-04-21  2:55         ` Sacha Chua
  0 siblings, 1 reply; 13+ messages in thread
From: Sebastien Vauban @ 2014-04-20 17:28 UTC (permalink / raw)
  To: emacs-orgmode-mXXj517/zsQ

Hello Sacha,

Sacha Chua wrote:
> Sebastien Vauban writes:
>
>>>> I would like to automatically count the number of children under a
>>>> given heading. For example, I would like to have
>>>> * Cars (2)
>>>> ** BMW
>>>> ** Escort
>>>
>>> There is no such feature in Org, but I seem to remember someone
>>> hack something similar -- maybe someone else with a better memory
>>> can tell.
>>
>> IIRC, Sacha Chua had made such a hack -- must be found on her impressive
>> blog.
>
> I don't remember doing something like that - I tend to use [X] for
> automatically counted cookies...
>
> Do you need the number of children to be part of the text, or is it
> okay for that to be temporarily displayed?

Yes, I almost remembered what you wrote in
http://sachachua.com/blog/2008/01/outlining-your-notes-with-org/,
section "Getting a Sense of Progress". Still, it is about counting
headlines, but with a special cookie you add.

Best regards,
  Seb

-- 
Sebastien Vauban

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Counting number of children under heading
  2014-04-20 17:28       ` Sebastien Vauban
@ 2014-04-21  2:55         ` Sacha Chua
  0 siblings, 0 replies; 13+ messages in thread
From: Sacha Chua @ 2014-04-21  2:55 UTC (permalink / raw)
  To: emacs-orgmode

Sebastien Vauban <sva-news@mygooglest.com>
writes:

Hello, Seb, all!

> Yes, I almost remembered what you wrote in
> http://sachachua.com/blog/2008/01/outlining-your-notes-with-org/,
> section "Getting a Sense of Progress". Still, it is about counting
> headlines, but with a special cookie you add.

Wow, I totally forgot about that. =) Good thing you remembered!

Anyway, Marvin, you (or someone) will probably be able to update that
code and get it to work for you, if you don't mind having checkboxes
instead of TODO. If you want it to work for plain headings, we could
probably figure out a custom function that updates numbers in
parentheses with the number of child headings. (Assuming you don't have
numbers in parentheses generally, or maybe we should use curly braces
instead? Decisions, decisions...) It's likely to be code that's going to
be in your custom config, since the need seems uncommon. =)

Sacha

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-04-21  2:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-17 13:44 Counting number of children under heading Marvin Doyley
2014-04-17 14:43 ` Thorsten Jolitz
  -- strict thread matches above, loose matches on Subject: below --
2014-04-17 16:21 Doyley, Marvin M.
2014-04-17  9:15 Marvin Doyley
2014-04-17  9:21 ` Bastien
2014-04-17  9:42   ` Thorsten Jolitz
2014-04-18 13:54   ` Sebastien Vauban
2014-04-18 14:50     ` Sacha Chua
2014-04-20 17:28       ` Sebastien Vauban
2014-04-21  2:55         ` Sacha Chua
2014-04-17 10:55 ` Eric Abrahamsen
2014-04-17 12:02   ` Thorsten Jolitz
2014-04-17 13:10     ` Eric Abrahamsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).