[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] Weight of headers
From: |
Nicolas Goaziou |
Subject: |
Re: [O] Weight of headers |
Date: |
Sun, 26 Feb 2012 13:30:36 +0100 |
Hello,
address@hidden (François 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.
#+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-block)
(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,
--
Nicolas Goaziou