[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Orgmode] Re: Context-sensitive word count in org mode (elisp)
From: |
Paul Sexton |
Subject: |
[Orgmode] Re: Context-sensitive word count in org mode (elisp) |
Date: |
Wed, 16 Feb 2011 20:34:15 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Christian Moe <mail <at> christianmoe.com> writes:
>
> Forgot to add the code.
>
> #+begin_src emacs-lisp
> ;; Adapted from code posted by Paul Sexton <2011-02-16 Wed 4:51am>
> ;; - Everything now contained in one function
> ;; - Will count correct number of words inside Latex macro
>
> (defun org-word-count (beg end)
> (interactive "r")
> (unless mark-active
> (setf beg (point-min)
> end (point-max)))
> (let ((wc 0)
> (latex-macro-regexp "\\\\[A-Za-z]+\\(\\[[^]]*\\]\\|
> \\){\\([^}]*\\)}")) ; CHANGED
> (save-excursion
> (goto-char beg)
> (while (< (point) end)
> (re-search-forward "\\w+\\W*")
> (cond
> ((or (org-in-commented-line) (org-at-table-p)) ; CHANGED
> nil)
> ((looking-at org-any-link-re)
> (goto-char (match-end 0)))
> ((save-excursion
> (backward-char)
> (looking-at latex-macro-regexp))
> (goto-char (match-beginning 2)) ; CHANGED
> (setf wc (+ 2 wc)))
> (t
> (incf wc)))))
> (message (format "%d words in %s." wc
> (if mark-active "region" "buffer")))))
> #+end_src
>
Thanks, I wasn't aware of those pre-existing functions.
I don't agree with changing '(match-end 0)' to '(match-beginning 2)'
however. For most latex macros, I don't want to count the words inside
the macro's arguments. For example, I don't want the next of footnotes
to be included in the word count. However others differ, and there will
always be cases where one DOES want to count the macro arguments - so maybe
org-word-count should do this optionally.
Paul