emacs-diffs
[Top][All Lists]
Advanced

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

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


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r105698: * lisp/simple.el (count-words-region): Use buffer if there's no region.
Date: Fri, 09 Sep 2011 23:02:06 -0400
User-agent: Bazaar (2.3.1)

------------------------------------------------------------
revno: 105698
author: Reuben Thomas <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2011-09-09 23:02:06 -0400
message:
  * lisp/simple.el (count-words-region): Use buffer if there's no region.
modified:
  lisp/ChangeLog
  lisp/simple.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-09-09 15:49:00 +0000
+++ b/lisp/ChangeLog    2011-09-10 03:02:06 +0000
@@ -1,3 +1,7 @@
+2011-09-10  Reuben Thomas  <address@hidden>
+
+       * simple.el (count-words-region): Use buffer if there's no region.
+
 2011-09-09  Juri Linkov  <address@hidden>
 
        * wdired.el (wdired-change-to-wdired-mode): Set buffer-local

=== modified file 'lisp/simple.el'
--- a/lisp/simple.el    2011-09-09 08:59:51 +0000
+++ b/lisp/simple.el    2011-09-10 03:02:06 +0000
@@ -938,9 +938,10 @@
       (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")
+  "Count the number of words in the active region.
+If the region is not active, counts the number of words in the buffer."
+  (interactive (if (use-region-p) (list (region-beginning) (region-end))
+                 (list (point-min) (point-max))))
   (let ((count 0))
     (save-excursion
       (save-restriction
@@ -948,8 +949,10 @@
         (goto-char (point-min))
         (while (forward-word 1)
           (setq count (1+ count)))))
-    (if (called-interactively-p 'interactive)
-        (message "Region has %d words" count))
+    (when (called-interactively-p 'interactive)
+      (message "%s has %d words"
+               (if (use-region-p) "Region" "Buffer")
+               count))
     count))
 
 (defun count-lines-region (start end)
@@ -983,12 +986,12 @@
       (if (eq selective-display t)
          (save-match-data
            (let ((done 0))
-             (while (re-search-forward "[\n\C-m]" nil t 40)
-               (setq done (+ 40 done)))
-             (while (re-search-forward "[\n\C-m]" nil t 1)
-               (setq done (+ 1 done)))
-             (goto-char (point-max))
-             (if (and (/= start end)
+                     (while (re-search-forward "[\n\C-m]" nil t 40)
+                       (setq done (+ 40 done)))
+                     (while (re-search-forward "[\n\C-m]" nil t 1)
+                       (setq done (+ 1 done)))
+                     (goto-char (point-max))
+                     (if (and (/= start end)
                       (not (bolp)))
                  (1+ done)
                done)))


reply via email to

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