diff options
| author | Reuben Thomas <rrt@sc3d.org> | 2011-09-09 23:02:06 -0400 |
|---|---|---|
| committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2011-09-09 23:02:06 -0400 |
| commit | fece895eff459a78403e5d92d5c960b54ee6bc4c (patch) | |
| tree | 46dae67a471d3de6fac5a6ca6caf8d0878158820 /lisp | |
| parent | 5e68ce4ab9bb6cdc8dc7aa3bbac014c93297369a (diff) | |
| download | emacs-fece895eff459a78403e5d92d5c960b54ee6bc4c.tar.gz | |
* lisp/simple.el (count-words-region): Use buffer if there's no region.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/simple.el | 25 |
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 @@ +2011-09-10 Reuben Thomas <rrt@sc3d.org> + + * simple.el (count-words-region): Use buffer if there's no region. + 2011-09-09 Juri Linkov <juri@jurta.org> * 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." (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 @@ When called interactively, the word count is printed in echo area." (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 @@ and the greater of them is not at the start of a line." (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))) |
