* lisp/simple.el (count-words-region): Use buffer if there's no region.
This commit is contained in:
parent
5e68ce4ab9
commit
fece895eff
2 changed files with 18 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
|
|
Loading…
Add table
Reference in a new issue