]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/simple.el (count-words-region): New function.
authorHrvoje Niksic <hniksic@xemacs.org>
Sat, 13 Nov 2010 03:46:00 +0000 (19:46 -0800)
committerGlenn Morris <rgm@gnu.org>
Sat, 13 Nov 2010 03:46:00 +0000 (19:46 -0800)
From: http://lists.gnu.org/archive/html/emacs-devel/2006-09/msg01029.html

lisp/ChangeLog
lisp/simple.el

index 7bafc8f0cb0bd1ea54bbafbd1c0520ccf1de596c..5442e0b26daa17e1be2249fc5302b4e7685119ee 100644 (file)
@@ -1,3 +1,7 @@
+2010-11-13  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * simple.el (count-words-region): New function.
+
 2010-11-12  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * shell.el (shell-dir-cookie-re): New custom variable.
index 510fb4a3b235e0d6ddeba43e8a4b279ec3e9a1be..55118553fbf21333b8e4f846a3b263cdaaec3428 100644 (file)
@@ -973,6 +973,21 @@ rather than line counts."
        (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")