Re: [O] Implemented word count for subtrees
El Thu, 28 Apr 2011 09:53:17 +0200 Sébastien Vauban va escriure: Another suggestion: a variable to choose between a word-count and a line-count? Or page-count. With a rough estimator that can predict how many pages each section would take. (Maybe even invoking LaTeX?) This feature is the one I most missed when I had to write a thesis where each section had to have a known number of pages (e.g. introduction 1 page, chapter 1 10 pages, … total 60 pages). I see it as useful enough to go in /contrib/ Many thanks!
Re: [O] Implemented word count for subtrees
Simon Guest simon.gu...@tesujimath.org writes: At Wed, 27 Apr 2011 18:51:06 +0100, Eric S Fraga wrote: This is quite nice. Thanks! I cannot help you with the mark problem; hopefully others can. One suggestion, however: I wonder if you could introduce the word count in a different way? I do use my headings and having the dots and the actual count inserted is not great (although easy work around: org-wc-display and then undo immediately after looking at the counts...). Maybe you could automatically define a tag for each heading, something like :wc:? Of course, this won't be good for anybody that wishes to export documents *with* tags... Anyway, I've incorporated your code into my emacs configuration. Thanks again! Hi Eric, Thanks for your comments. The counts are not actually inserted as text in the file. It's just an overlay, done with text properties like the clock durations (from where I stole the code). They don't get saved in the file, and in fact as soon as you edit the buffer, they all disappear. At least, they do for me. Does it do something different for you? If so, it may be something to do with the file coding system that is letting them get saved. Is your Org mode file a simple ASCII file, or something else? Ah, I see that the counts do disappear as soon as I do anything. My confusion came about because as soon as I invoke =org-wc-display=, my buffer becomes /modified/ which led me believe that the counts were actually inserted into the document.As they are not inserted, please ignore my previous comments. However, it would be helpful if the modification flag were not changed by asking for the word count. I don't know enough elisp to suggest what to change but you should be able to add the text properties without causing the buffer modification flag to change? Column view, for instance, doesn't do this. Thanks again, eric -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.209.g1a687)
Re: [O] Implemented word count for subtrees
Sébastien Vauban wxhgmqzgw...@spammotel.com writes: Hi Simon, Simon Guest wrote: Dear Org mode people, I implemented word counting for Org mode sub-trees. That is, count each sub-tree, and accumulate totals into the parent heading lines. Others have asked about this, so I attach my code below. Another suggestion: a variable to choose between a word-count and a line-count? Or display both at the same time? =NNN/MM=? -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.209.g1a687)
Re: [O] Implemented word count for subtrees
Simon Guest simon.gu...@tesujimath.org writes: Dear Org mode people, I implemented word counting for Org mode sub-trees. That is, count each sub-tree, and accumulate totals into the parent heading lines. Others have asked about this, so I attach my code below. This is quite nice. Thanks! I cannot help you with the mark problem; hopefully others can. One suggestion, however: I wonder if you could introduce the word count in a different way? I do use my headings and having the dots and the actual count inserted is not great (although easy work around: org-wc-display and then undo immediately after looking at the counts...). Maybe you could automatically define a tag for each heading, something like :wc:? Of course, this won't be good for anybody that wishes to export documents *with* tags... Anyway, I've incorporated your code into my emacs configuration. Thanks again! -- : Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1 : using Org-mode version 7.5 (release_7.5.211.gb0094)
Re: [O] Implemented word count for subtrees
At Wed, 27 Apr 2011 18:51:06 +0100, Eric S Fraga wrote: This is quite nice. Thanks! I cannot help you with the mark problem; hopefully others can. One suggestion, however: I wonder if you could introduce the word count in a different way? I do use my headings and having the dots and the actual count inserted is not great (although easy work around: org-wc-display and then undo immediately after looking at the counts...). Maybe you could automatically define a tag for each heading, something like :wc:? Of course, this won't be good for anybody that wishes to export documents *with* tags... Anyway, I've incorporated your code into my emacs configuration. Thanks again! Hi Eric, Thanks for your comments. The counts are not actually inserted as text in the file. It's just an overlay, done with text properties like the clock durations (from where I stole the code). They don't get saved in the file, and in fact as soon as you edit the buffer, they all disappear. At least, they do for me. Does it do something different for you? If so, it may be something to do with the file coding system that is letting them get saved. Is your Org mode file a simple ASCII file, or something else? cheers, Simon
[O] Implemented word count for subtrees
Dear Org mode people, I implemented word counting for Org mode sub-trees. That is, count each sub-tree, and accumulate totals into the parent heading lines. Others have asked about this, so I attach my code below. I started with Paul Sexton's code posted to the list on 21/2/11. I had some different requirements, so I hacked this mercilessly. Sorry, Paul. I was most concerned about speed, so I removed any check that caused repeated hunting around in the org mode buffer - all the contextual stuff. I also skip heading lines, as I didn't want them in my total. (I'm using the wonderful Org mode to write a novel, and the heading lines are for my organisation only, not part of the text.) Anyway, here it is. I use this key-binding in my .emacs. (define-key org-mode-map \C-c\C-xw 'org-wc-display) By the way, it complains if you call it without mark being set. I want to use (interactive r) to handle regions, but don't know how to handle this error case. Suggestions welcome. cheers, Simon ;; org-wc.el ;; ;; Count words in org mode trees. ;; Shows word count per heading line, summed over sub-headings. ;; Aims to be fast, so doesn't check carefully what it's counting. ;-) ;; ;; Simon Guest, 23/4/11 ;; ;; Implementation based on: ;; - Paul Sexton's word count posted on org-mode mailing list 21/2/11. ;; - clock overlays (defun org-in-heading-line () Is point in a line starting with `*'? (equal (char-after (point-at-bol)) ?*)) (defun org-word-count (beg end) Report the number of words in the Org mode buffer or selected region. (interactive r) (unless mark-active (setf beg (point-min) end (point-max))) (let ((wc (org-word-count-aux beg end))) (message (format %d words in %s. wc (if mark-active region buffer) (defun org-word-count-aux (beg end) Report the number of words in the selected region. Ignores: heading lines, blocks, comments, drawers. LaTeX macros are counted as 1 word. (let ((wc 0) (block-begin-re ^#\\\+BEGIN) (block-end-re ^#\\+END) (latex-macro-regexp [A-Za-z]+\\(\\[[^]]*\\]\\|\\){\\([^}]*\\)}) (drawers-re (concat ^[ \t]*:\\( (mapconcat 'regexp-quote org-drawers \\|) \\):[ \t]*$)) (drawers-end-re ^[ \t]*:END:)) (save-excursion (goto-char beg) (while ( (point) end) (cond ;; Ignore heading lines. ((org-in-heading-line) (forward-line)) ;; Ignore blocks. ((looking-at block-begin-re) (re-search-forward block-end-re)) ;; Ignore comments. ((org-in-commented-line) (forward-line)) ;; Ignore drawers. ((looking-at drawers-re) (re-search-forward drawers-end-re nil t)) ;; Count latex macros as 1 word, ignoring their arguments. ((save-excursion (backward-char) (looking-at latex-macro-regexp)) (goto-char (match-end 0)) (setf wc (+ 2 wc))) (t (progn (re-search-forward \\w+\\W*) (incf wc)) wc)) (defun org-wc-count-subtrees () Count words in each subtree, putting result as the property :org-wc on that heading. (interactive) (remove-text-properties (point-min) (point-max) '(:org-wc t)) (save-excursion (goto-char (point-max)) (while (outline-previous-heading) (org-narrow-to-subtree) (let ((wc (org-word-count-aux (point-min) (point-max (put-text-property (point) (point-at-eol) :org-wc wc) (goto-char (point-min)) (widen) (defun org-wc-display (beg end total-only) Show subtree word counts in the entire buffer. With prefix argument, only show the total wordcount for the buffer or region in the echo area. Use \\[org-wc-remove-overlays] to remove the subtree times. Ignores: heading lines, blocks, comments, drawers. LaTeX macros are counted as 1 word. (interactive r\nP) (org-wc-remove-overlays) (unless total-only (let (wc p) (org-wc-count-subtrees) (save-excursion (goto-char (point-min)) (while (or (and (equal (setq p (point)) (point-min)) (get-text-property p :org-wc)) (setq p (next-single-property-change (point) :org-wc))) (goto-char p) (when (setq wc (get-text-property p :org-wc)) (org-wc-put-overlay wc (funcall outline-level ;; Arrange to remove the overlays upon next change. (when org-remove-highlights-with-change (org-add-hook 'before-change-functions 'org-wc-remove-overlays nil 'local) (if mark-active (org-word-count beg end) (org-word-count (point-min) (point-max (defvar org-wc-overlays nil) (make-variable-buffer-local 'org-wc-overlays) (defun