aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHrvoje Niksic2010-11-12 19:46:00 -0800
committerGlenn Morris2010-11-12 19:46:00 -0800
commit8da5345fed03743eb7092f67766095460b758686 (patch)
tree4d6514427529f92b4140f389c94cffc904e9e965
parenta7cfbaea04e1720e93fe60dedfcfabd544d63882 (diff)
downloademacs-8da5345fed03743eb7092f67766095460b758686.tar.gz
emacs-8da5345fed03743eb7092f67766095460b758686.zip
* lisp/simple.el (count-words-region): New function.
From: http://lists.gnu.org/archive/html/emacs-devel/2006-09/msg01029.html
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/simple.el15
2 files changed, 19 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7bafc8f0cb0..5442e0b26da 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12010-11-13 Hrvoje Niksic <hniksic@xemacs.org>
2
3 * simple.el (count-words-region): New function.
4
12010-11-12 Stefan Monnier <monnier@iro.umontreal.ca> 52010-11-12 Stefan Monnier <monnier@iro.umontreal.ca>
2 6
3 * shell.el (shell-dir-cookie-re): New custom variable. 7 * 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."
973 (re-search-forward "[\n\C-m]" nil 'end (1- line)) 973 (re-search-forward "[\n\C-m]" nil 'end (1- line))
974 (forward-line (1- line))))) 974 (forward-line (1- line)))))
975 975
976(defun count-words-region (start end)
977 "Print the number of words in the region.
978When called interactively, the word count is printed in echo area."
979 (interactive "r")
980 (let ((count 0))
981 (save-excursion
982 (save-restriction
983 (narrow-to-region start end)
984 (goto-char (point-min))
985 (while (forward-word 1)
986 (setq count (1+ count)))))
987 (if (interactive-p)
988 (message "Region has %d words" count))
989 count))
990
976(defun count-lines-region (start end) 991(defun count-lines-region (start end)
977 "Print number of lines and characters in the region." 992 "Print number of lines and characters in the region."
978 (interactive "r") 993 (interactive "r")