From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Weight of headers Date: Sun, 26 Feb 2012 13:30:36 +0100 Message-ID: <874nudhj4j.fsf@gmail.com> References: <8762euxqli.fsf@iro.umontreal.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([208.118.235.92]:49642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1dHk-0008S7-RG for emacs-orgmode@gnu.org; Sun, 26 Feb 2012 07:33:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S1dHe-0005LB-Su for emacs-orgmode@gnu.org; Sun, 26 Feb 2012 07:33:04 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:37430) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1dHe-0005L4-Ly for emacs-orgmode@gnu.org; Sun, 26 Feb 2012 07:32:58 -0500 Received: by wibhj13 with SMTP id hj13so3053866wib.0 for ; Sun, 26 Feb 2012 04:32:57 -0800 (PST) In-Reply-To: <8762euxqli.fsf@iro.umontreal.ca> (=?utf-8?Q?=22Fran=C3=A7ois?= Pinard"'s message of "Sat, 25 Feb 2012 21:42:33 -0500") 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-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: =?utf-8?Q?Fran=C3=A7ois?= Pinard Cc: emacs-orgmode@gnu.org Hello, pinard@iro.umontreal.ca (Fran=C3=A7ois Pinard) writes: > Here is a need I have once in a while, but for which I do not even have > realistic suggestions to offer (at least, so I feel). Maybe someone > would offer more precise ideas. :-) > > When I have a big Org file which I want to re-organize, one of the > criteria I use is to manage the overall plan, always keeping a logical > organization of things of course, and move things around so top-level > headers become of comparable weights. By "weight", I mean the amount of > contents, which is a fuzzy concept (it could be measured as the number > of sub-headers or sub-items, the depth of structure, or even the raw > number or lines or characters). > > It may look strange, but this is not so bizarre after all. When reading > a book, it is unusual to have a chapter having one page next to a > chapter having hundreds of page; we expect that the effort of reading a > chapter is not widely different from the effort of reading another. In > the same way, if I decide to tackle the topics under a header, I would > expect that the energy needed somehow announces the energy that would be > required to handle another level at the same level. Of course, there > could be quite a variance, but nevertheless, I would like to keep that > variance within bounds. > > And recursively! The same way I would like to work an weight > equilibrium for top-level headers, I would like to do the same for the > sub-headers of a given header. > > My need here is to get an estimate of the weight of displayed headers. > I could of course expand the whole document and page through to get an > idea, but at least in the document I'm currently handling, I'm just > overwhelmed. (This is not the only document triggering this in me, I > remember having felt that need many times when I was using WorkFlowy). > > I once thought that colors could encode the weight, but it just would > not fit Org mode so far that I understand it. However, it seems that, > here and there, Org uses some overly magic to display extra information > -- for example, like with `C-c C-x C-d (`org-clock-display')'. Maybe > that some similar machinery could be use to display header weights? Or > maybe this would be overkill, because there are simpler ways which I > just do not know? The following function will give you the number of sub-headings and paragraphs (or equivalent, i.e. tables verse-blocks....). You'll need a recent Org to use it.=20 #+begin_src emacs-lisp (defun pinard-count-subtree-and-paragraphs () "Return number of subtrees and paragraphs in the subtree at point." (interactive) (org-with-wide-buffer (org-narrow-to-subtree) (let ((tree (org-element-parse-buffer 'element)) (num-hl 0) (num-el 0)) (org-element-map tree 'headline (lambda (hl) (incf num-hl))) (org-element-map tree '(paragraph table verse-block quote-block src-block example-bloc= k) (lambda (el) (incf num-el))) (message "Sub-headings: %d ; Parapraphs (or equivalent): %d" (1- num-hl) num-el)))) #+end_src There's no colour, but it's a starter. Regards, --=20 Nicolas Goaziou