[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r107507: Tweaks to count-words and co
From: |
Chong Yidong |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r107507: Tweaks to count-words and count-words-region behavior. |
Date: |
Mon, 05 Mar 2012 14:10:11 +0800 |
User-agent: |
Bazaar (2.3.1) |
------------------------------------------------------------
revno: 107507
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Mon 2012-03-05 14:10:11 +0800
message:
Tweaks to count-words and count-words-region behavior.
In particular, make count-words more analogous to the existing
count-lines function.
* lisp/simple.el (count-words): If called from Lisp, return the word
count, for symmetry with `count-lines'. Arglist changed.
(count-words--message): Args changed. Consolidate counting code
from count-words and count-words-region.
(count-words-region): Caller changed.
(count-lines-region): Make it an obsolete alias.
modified:
etc/NEWS
lisp/ChangeLog
lisp/simple.el
=== modified file 'etc/NEWS'
--- a/etc/NEWS 2012-03-05 03:13:46 +0000
+++ b/etc/NEWS 2012-03-05 06:10:11 +0000
@@ -483,9 +483,12 @@
+++
** New commands `count-words-region' and `count-words'.
-
-*** `count-lines-region' is now an alias for `count-words-region',
-bound to M-=, which shows the number of lines, words, and characters.
++++
+*** M-= is bound to `count-words-region', not `count-lines-region'.
+The `count-words-region' command, when called interactively, reports
+the number of lines, words, and characters in the region. It is a
+superset of the old `count-lines-region', which is now an obsolete
+alias for it.
+++
** The default value of `backup-by-copying-when-mismatch' is now t.
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2012-03-04 16:56:21 +0000
+++ b/lisp/ChangeLog 2012-03-05 06:10:11 +0000
@@ -1,3 +1,12 @@
+2012-03-05 Chong Yidong <address@hidden>
+
+ * simple.el (count-words): If called from Lisp, return the word
+ count, for symmetry with `count-lines'. Arglist changed.
+ (count-words--message): Args changed. Consolidate counting code
+ from count-words and count-words-region.
+ (count-words-region): Caller changed.
+ (count-lines-region): Make it an obsolete alias.
+
2012-03-04 Tassilo Horn <address@hidden>
* saveplace.el (save-place-to-alist)
=== modified file 'lisp/simple.el'
--- a/lisp/simple.el 2012-02-13 19:42:58 +0000
+++ b/lisp/simple.el 2012-03-05 06:10:11 +0000
@@ -949,46 +949,51 @@
(forward-line (1- line)))))
(defun count-words-region (start end)
- "Return the number of words between START and END.
+ "Count the number of words in the region.
If called interactively, print a message reporting the number of
-lines, words, and characters in the region."
+lines, words, and chars in the region.
+If called from Lisp, return the number of words between positions
+START and END."
(interactive "r")
- (let ((words 0))
- (save-excursion
- (save-restriction
- (narrow-to-region start end)
- (goto-char (point-min))
- (while (forward-word 1)
- (setq words (1+ words)))))
- (when (called-interactively-p 'interactive)
- (count-words--message "Region"
- (count-lines start end)
- words
- (- end start)))
- words))
-
-(defun count-words ()
- "Display the number of lines, words, and characters in the buffer.
-In Transient Mark mode when the mark is active, display the
-number of lines, words, and characters in the region."
- (interactive)
- (if (use-region-p)
- (call-interactively 'count-words-region)
- (let* ((beg (point-min))
- (end (point-max))
- (lines (count-lines beg end))
- (words (count-words-region beg end))
- (chars (- end beg)))
- (count-words--message "Buffer" lines words chars))))
-
-(defun count-words--message (str lines words chars)
- (message "%s has %d line%s, %d word%s, and %d character%s."
- str
- lines (if (= lines 1) "" "s")
- words (if (= words 1) "" "s")
- chars (if (= chars 1) "" "s")))
-
-(defalias 'count-lines-region 'count-words-region)
+ (if (called-interactively-p 'any)
+ (count-words--message "Region" start end)
+ (count-words start end)))
+
+(defun count-words (start end)
+ "Count words between START and END.
+If called interactively, START and END are normally the start and
+end of the buffer; but if the region is active, START and END are
+the start and end of the region. Print a message reporting the
+number of lines, words, and chars.
+
+If called from Lisp, return the number of words between START and
+END, without printing any message."
+ (interactive (list nil nil))
+ (cond ((not (called-interactively-p 'any))
+ (let ((words 0))
+ (save-excursion
+ (save-restriction
+ (narrow-to-region start end)
+ (goto-char (point-min))
+ (while (forward-word 1)
+ (setq words (1+ words)))))
+ words))
+ ((use-region-p)
+ (call-interactively 'count-words-region))
+ (t
+ (count-words--message "Buffer" (point-min) (point-max)))))
+
+(defun count-words--message (str start end)
+ (let ((lines (count-lines start end))
+ (words (count-words start end))
+ (chars (- end start)))
+ (message "%s has %d line%s, %d word%s, and %d character%s."
+ str
+ lines (if (= lines 1) "" "s")
+ words (if (= words 1) "" "s")
+ chars (if (= chars 1) "" "s"))))
+
+(define-obsolete-function-alias 'count-lines-region 'count-words-region "24.1")
(defun what-line ()
"Print the current buffer line number and narrowed line number of point."
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] /srv/bzr/emacs/trunk r107507: Tweaks to count-words and count-words-region behavior.,
Chong Yidong <=