emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r102370: * lisp/simple.el (count-word


From: Glenn Morris
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r102370: * lisp/simple.el (count-words-region): New function.
Date: Fri, 12 Nov 2010 19:46:00 -0800
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 102370
author: Hrvoje Niksic <address@hidden>
committer: Glenn Morris <address@hidden>
branch nick: trunk
timestamp: Fri 2010-11-12 19:46:00 -0800
message:
  * lisp/simple.el (count-words-region): New function.
  
  From: http://lists.gnu.org/archive/html/emacs-devel/2006-09/msg01029.html
modified:
  lisp/ChangeLog
  lisp/simple.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2010-11-13 03:36:32 +0000
+++ b/lisp/ChangeLog    2010-11-13 03:46:00 +0000
@@ -1,3 +1,7 @@
+2010-11-13  Hrvoje Niksic  <address@hidden>
+
+       * simple.el (count-words-region): New function.
+
 2010-11-12  Stefan Monnier  <address@hidden>
 
        * shell.el (shell-dir-cookie-re): New custom variable.

=== modified file 'lisp/simple.el'
--- a/lisp/simple.el    2010-11-12 13:32:02 +0000
+++ b/lisp/simple.el    2010-11-13 03:46:00 +0000
@@ -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")


reply via email to

[Prev in Thread] Current Thread [Next in Thread]