From 8da5345fed03743eb7092f67766095460b758686 Mon Sep 17 00:00:00 2001 From: Hrvoje Niksic Date: Fri, 12 Nov 2010 19:46:00 -0800 Subject: [PATCH] * lisp/simple.el (count-words-region): New function. From: http://lists.gnu.org/archive/html/emacs-devel/2006-09/msg01029.html --- lisp/ChangeLog | 4 ++++ lisp/simple.el | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7bafc8f0cb0..5442e0b26da 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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 --git a/lisp/simple.el b/lisp/simple.el index 510fb4a3b23..55118553fbf 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -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") -- 2.39.2