all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Count words under subtrees
@ 2016-09-27  9:01 Giacomo M
  2016-09-27 18:52 ` Thorsten Jolitz
  2016-09-28 22:54 ` Adam Porter
  0 siblings, 2 replies; 7+ messages in thread
From: Giacomo M @ 2016-09-27  9:01 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

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

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

* Re: Count words under subtrees
       [not found] <13cda52050fc411c8b0b7a74bd60f5c0@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
@ 2016-09-27  9:15 ` Eric S Fraga
  2016-09-27  9:18 ` Eric S Fraga
  1 sibling, 0 replies; 7+ messages in thread
From: Eric S Fraga @ 2016-09-27  9:15 UTC (permalink / raw)
  To: Giacomo M; +Cc: emacs-orgmode@gnu.org

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

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

* Re: Count words under subtrees
       [not found] <13cda52050fc411c8b0b7a74bd60f5c0@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
  2016-09-27  9:15 ` Eric S Fraga
@ 2016-09-27  9:18 ` Eric S Fraga
  1 sibling, 0 replies; 7+ messages in thread
From: Eric S Fraga @ 2016-09-27  9:18 UTC (permalink / raw)
  To: Giacomo M; +Cc: emacs-orgmode@gnu.org

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

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

* Re: Count words under subtrees
  2016-09-27  9:01 Count words under subtrees Giacomo M
@ 2016-09-27 18:52 ` Thorsten Jolitz
  2016-09-28 22:54 ` Adam Porter
  1 sibling, 0 replies; 7+ messages in thread
From: Thorsten Jolitz @ 2016-09-27 18:52 UTC (permalink / raw)
  To: emacs-orgmode

Giacomo M <jackjackk@gmail.com> 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

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

* Re: Count words under subtrees
  2016-09-27  9:01 Count words under subtrees Giacomo M
  2016-09-27 18:52 ` Thorsten Jolitz
@ 2016-09-28 22:54 ` Adam Porter
  2016-09-28 23:05   ` Adam Porter
  1 sibling, 1 reply; 7+ messages in thread
From: Adam Porter @ 2016-09-28 22:54 UTC (permalink / raw)
  To: emacs-orgmode

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...

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

* Re: Count words under subtrees
  2016-09-28 22:54 ` Adam Porter
@ 2016-09-28 23:05   ` Adam Porter
  2016-09-28 23:22     ` Adam Porter
  0 siblings, 1 reply; 7+ messages in thread
From: Adam Porter @ 2016-09-28 23:05 UTC (permalink / raw)
  To: emacs-orgmode

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.  :)

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

* Re: Count words under subtrees
  2016-09-28 23:05   ` Adam Porter
@ 2016-09-28 23:22     ` Adam Porter
  0 siblings, 0 replies; 7+ messages in thread
From: Adam Porter @ 2016-09-28 23:22 UTC (permalink / raw)
  To: emacs-orgmode

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

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

end of thread, other threads:[~2016-09-28 23:23 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-27  9:01 Count words under subtrees Giacomo M
2016-09-27 18:52 ` Thorsten Jolitz
2016-09-28 22:54 ` Adam Porter
2016-09-28 23:05   ` Adam Porter
2016-09-28 23:22     ` Adam Porter
     [not found] <13cda52050fc411c8b0b7a74bd60f5c0@HE1PR01MB1898.eurprd01.prod.exchangelabs.com>
2016-09-27  9:15 ` Eric S Fraga
2016-09-27  9:18 ` Eric S Fraga

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.