# HG changeset patch # User Glenn Morris # Date 1289619960 28800 # Node ID 3855698b7f05c0fe21b8f611afef72a78efb5d4e # Parent f5486a22b31a261bdc60e83a1bc26ebe4272b24d * lisp/simple.el (count-words-region): New function. From: http://lists.gnu.org/archive/html/emacs-devel/2006-09/msg01029.html diff -r f5486a22b31a -r 3855698b7f05 lisp/ChangeLog --- a/lisp/ChangeLog Fri Nov 12 19:36:32 2010 -0800 +++ b/lisp/ChangeLog Fri Nov 12 19:46:00 2010 -0800 @@ -1,3 +1,7 @@ +2010-11-13 Hrvoje Niksic + + * simple.el (count-words-region): New function. + 2010-11-12 Stefan Monnier * shell.el (shell-dir-cookie-re): New custom variable. diff -r f5486a22b31a -r 3855698b7f05 lisp/simple.el --- a/lisp/simple.el Fri Nov 12 19:36:32 2010 -0800 +++ b/lisp/simple.el Fri Nov 12 19:46:00 2010 -0800 @@ -973,6 +973,21 @@ (re-search-forward "[\n\C-m]" nil 'end (1- line)) (forward-line (1- line))))) +(defun count-words-region (start end) + "Print the number of words in the region. +When called interactively, the word count is printed in echo area." + (interactive "r") + (let ((count 0)) + (save-excursion + (save-restriction + (narrow-to-region start end) + (goto-char (point-min)) + (while (forward-word 1) + (setq count (1+ count))))) + (if (interactive-p) + (message "Region has %d words" count)) + count)) + (defun count-lines-region (start end) "Print number of lines and characters in the region." (interactive "r")