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 _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode