Re: [O] Count words under subtrees

2016-09-28 Thread Adam Porter
Forgive the triple-posting; one of these days I'll learn to wait a bit
longer before sharing.  Anyway, this updated function will avoid
counting the words in drawers and keyword-time lines
(e.g. "SCHEDULED:").

Let me know if you find anything else it needs to handle.  Skipping
source blocks is an idea, but it would be more complex.  This is
probably good enough for most uses.  :)

#+BEGIN_SRC elisp
  (defun org-count-words-in-subtree ()
"Count words in current node and child nodes, excluding heading
  text."
(interactive)
(save-excursion
  (save-restriction
(widen)
(message "%s words in subtree"
 (-sum (org-map-entries (lambda ()
  (outline-back-to-heading)
  (forward-line 1)
  (while (or (looking-at 
org-keyword-time-regexp)
 (org-in-drawer-p))
(forward-line 1))
  (count-words (point)
   (progn
 
(outline-end-of-subtree)
 (point
nil 'tree))
#+END_SRC




Re: [O] Count words under subtrees

2016-09-28 Thread Adam Porter
You might find this useful as well:

#+BEGIN_SRC elisp
(defun count-words-in-subtree-or-region ()
(interactive)
(call-interactively (if (region-active-p)
'count-words-region
  'count-words-in-subtree)))
#+END_SRC

I bound that to M-= in org-mode to replace the default count-words, so
now one command does both.  :)




Re: [O] Count words under subtrees

2016-09-28 Thread Adam Porter
I think this should do it:

#+BEGIN_SRC elisp
  (defun count-words-in-subtree ()
"Count words in current node and child nodes, excluding heading
  text."
(interactive)
(save-excursion
  (save-restriction
(widen)
(message "%s words"
 (-sum (org-map-entries (lambda ()
  (outline-back-to-heading)
  (forward-line 1)
  (count-words (point)
   (progn
 
(outline-end-of-subtree)
 (point
nil 'tree))
#+END_SRC

I haven't tested it extensively, but it seems to work correctly,
counting the current node and any child nodes, but not going into
sibling nodes.  I've been thinking about doing this for a while now, so
thanks for reminding me!  :)

Oh, and it uses the dash.el library, which most Emacs users should
have...




Re: [O] Count words under subtrees

2016-09-27 Thread Thorsten Jolitz
Giacomo M  writes:

Hi,

> right now I manually =er/expand-region= (from expand-region.el) until
> I select a subtree, and then =count-words-region= to get number of
> words for the subtree. I was wondering whether anybody already coded
> some lisp to programmatically have this count, ideally one count per
> TOC entry (and perhaps excluding headline words in the count).

AFAIK there are two libraries that show the "weight" of a folded subtree
based on hidden lines as little headline cookies - if that helps. Not
sure about their state, they might just work:

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

and org-hlc is build into outshine, so if you open (e.g.) an elisp file
that is structured with outshine headers (= outcommented org-headers),
and have outshine minor-mode enabled, you can use

,[ C-h f outshine-toggle-hidden-lines-cookies RET ]
| outshine-toggle-hidden-lines-cookies is an interactive Lisp function
| in `outshine.el'.
| 
| (outshine-toggle-hidden-lines-cookies)
| 
| Toggles status of hidden-lines cookies between shown and hidden.
`

and will see something like this, i.e. folded headers with 'hidden lines
cookies':

,
|  55:;; * Prerequisites
|  56:;; ** Start Message and Start Time [#8]
|  65:;; ** Setup Parts :mytag: [#79]
| 145:;; ** Environment [#92]
| 238:;; ** Loading Emacs Lisp Libraries
| 239:;; *** Features [#64]
| 304:;; *** Library Search [#144]
| 449:;; *** Package Manager [#39]
| 489:;; *** Autoloads [#5]
| 495:;; ** Debugging [#8]
| 504:;; * [Screen Input Keys Cmd Enter Exit] [#1]
| 506:;; ** 1 (info "(emacs)Screen") [#3]
| 510:;; *** 1.1 (info "(emacs)Point")
| 511:;; *** 1.2 (info "(emacs)Echo Area") [#4]
| 516:;; *** 1.3 (info "(emacs)Mode Line") [#4]
| 521:;; *** 1.4 (info "(emacs)Menu Bar") [#2]
`


-- 
cheers,
Thorsten




Re: [O] Count words under subtrees

2016-09-27 Thread Eric S Fraga
On Tuesday, 27 Sep 2016 at 09:01, Giacomo M wrote:
> Dear all,
>
> right now I manually =er/expand-region= (from expand-region.el) until I 
> select a subtree, and then =count-words-region= to get number of words 
> for the subtree. I was wondering whether anybody already coded some lisp 
> to programmatically have this count, ideally one count per TOC entry 
> (and perhaps excluding headline words in the count).

Cannot help you directly although this topic has come up before on this
list.

However, I can point you to C-c @ (org-mark-subtree) as a quick way to
select the whole subtree which at least makes the process a little less
painful.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.1.50.1, Org release_8.3.6-1149-g582233



Re: [O] Count words under subtrees

2016-09-27 Thread Eric S Fraga
And you could always use one of the solutions presented here:

https://www.emacswiki.org/emacs/WordCount

to have the word count in the mode line.  Mark a subtree and
automatically see the word count.

-- 
: Eric S Fraga (0xFFFCF67D), Emacs 25.1.50.1, Org release_8.3.6-1149-g582233



[O] Count words under subtrees

2016-09-27 Thread Giacomo M

Dear all,

right now I manually =er/expand-region= (from expand-region.el) until I 
select a subtree, and then =count-words-region= to get number of words 
for the subtree. I was wondering whether anybody already coded some lisp 
to programmatically have this count, ideally one count per TOC entry 
(and perhaps excluding headline words in the count).


Thanks,

Giacomo