aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/simple.el25
2 files changed, 18 insertions, 11 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7b0b4890724..89b43bab43d 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12011-09-10 Reuben Thomas <rrt@sc3d.org>
2
3 * simple.el (count-words-region): Use buffer if there's no region.
4
12011-09-09 Juri Linkov <juri@jurta.org> 52011-09-09 Juri Linkov <juri@jurta.org>
2 6
3 * wdired.el (wdired-change-to-wdired-mode): Set buffer-local 7 * wdired.el (wdired-change-to-wdired-mode): Set buffer-local
diff --git a/lisp/simple.el b/lisp/simple.el
index 5b639f774cb..74343496c72 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -938,9 +938,10 @@ rather than line counts."
938 (forward-line (1- line))))) 938 (forward-line (1- line)))))
939 939
940(defun count-words-region (start end) 940(defun count-words-region (start end)
941 "Print the number of words in the region. 941 "Count the number of words in the active region.
942When called interactively, the word count is printed in echo area." 942If the region is not active, counts the number of words in the buffer."
943 (interactive "r") 943 (interactive (if (use-region-p) (list (region-beginning) (region-end))
944 (list (point-min) (point-max))))
944 (let ((count 0)) 945 (let ((count 0))
945 (save-excursion 946 (save-excursion
946 (save-restriction 947 (save-restriction
@@ -948,8 +949,10 @@ When called interactively, the word count is printed in echo area."
948 (goto-char (point-min)) 949 (goto-char (point-min))
949 (while (forward-word 1) 950 (while (forward-word 1)
950 (setq count (1+ count))))) 951 (setq count (1+ count)))))
951 (if (called-interactively-p 'interactive) 952 (when (called-interactively-p 'interactive)
952 (message "Region has %d words" count)) 953 (message "%s has %d words"
954 (if (use-region-p) "Region" "Buffer")
955 count))
953 count)) 956 count))
954 957
955(defun count-lines-region (start end) 958(defun count-lines-region (start end)
@@ -983,12 +986,12 @@ and the greater of them is not at the start of a line."
983 (if (eq selective-display t) 986 (if (eq selective-display t)
984 (save-match-data 987 (save-match-data
985 (let ((done 0)) 988 (let ((done 0))
986 (while (re-search-forward "[\n\C-m]" nil t 40) 989 (while (re-search-forward "[\n\C-m]" nil t 40)
987 (setq done (+ 40 done))) 990 (setq done (+ 40 done)))
988 (while (re-search-forward "[\n\C-m]" nil t 1) 991 (while (re-search-forward "[\n\C-m]" nil t 1)
989 (setq done (+ 1 done))) 992 (setq done (+ 1 done)))
990 (goto-char (point-max)) 993 (goto-char (point-max))
991 (if (and (/= start end) 994 (if (and (/= start end)
992 (not (bolp))) 995 (not (bolp)))
993 (1+ done) 996 (1+ done)
994 done))) 997 done)))