[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] /srv/bzr/emacs/trunk r106028: Rework count-words-region. N
From: |
Chong Yidong |
Subject: |
[Emacs-diffs] /srv/bzr/emacs/trunk r106028: Rework count-words-region. New command count-words. |
Date: |
Sat, 08 Oct 2011 12:37:46 -0400 |
User-agent: |
Bazaar (2.3.1) |
------------------------------------------------------------
revno: 106028
committer: Chong Yidong <address@hidden>
branch nick: trunk
timestamp: Sat 2011-10-08 12:37:46 -0400
message:
Rework count-words-region. New command count-words.
See discussion at
http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00193.html
* lisp/simple.el (count-words-region): Always count in the region.
Report the number of lines and characters too.
(count-words): New command, which counts in the buffer if the
region is inactive, as count-words-region used to.
(count-words--message): New function. Handle plurals.
(count-lines-region): Make it an alias for count-words-region.
* lisp/bindings.el (esc-map): Replace count-lines-region with
count-words-region.
* doc/emacs/basic.texi (Position Info): Omit page commands. Document
count-words-region and count-words.
* doc/emacs/text.texi (Pages): Move what-page documentation here.
modified:
doc/emacs/ChangeLog
doc/emacs/basic.texi
doc/emacs/emacs.texi
doc/emacs/text.texi
etc/NEWS
lisp/ChangeLog
lisp/bindings.el
lisp/simple.el
=== modified file 'doc/emacs/ChangeLog'
--- a/doc/emacs/ChangeLog 2011-10-08 15:08:50 +0000
+++ b/doc/emacs/ChangeLog 2011-10-08 16:37:46 +0000
@@ -1,5 +1,12 @@
2011-10-08 Chong Yidong <address@hidden>
+ * basic.texi (Position Info): Omit page commands. Document
+ count-words-region and count-words.
+
+ * text.texi (Pages): Move what-page documentation here.
+
+2011-10-08 Chong Yidong <address@hidden>
+
* mini.texi (Minibuffer File): Minor copyedits. Use xref to
Remote Files node instead of linking directly to the Tramp manual.
(Minibuffer Edit): Add xref to Blank Lines.
=== modified file 'doc/emacs/basic.texi'
--- a/doc/emacs/basic.texi 2011-10-07 16:22:04 +0000
+++ b/doc/emacs/basic.texi 2011-10-08 16:37:46 +0000
@@ -23,7 +23,7 @@
* Help: Basic Help. Asking what a character does.
* Blank Lines:: Making and deleting blank lines.
* Continuation Lines:: How Emacs displays lines too wide for the screen.
-* Position Info:: What page, line, row, or column is point on?
+* Position Info:: What line, row, or column is point on?
* Arguments:: Numeric arguments for repeating a command N times.
* Repeating:: Repeating the previous command quickly.
@end menu
@@ -569,28 +569,26 @@
@section Cursor Position Information
Here are commands to get information about the size and position of
-parts of the buffer, and to count lines.
+parts of the buffer, and to count words and lines.
@table @kbd
address@hidden M-x what-page
-Display the page number of point, and the line number within that page.
@item M-x what-line
-Display the line number of point in the whole buffer.
+Display the line number of point.
@item M-x line-number-mode
@itemx M-x column-number-mode
Toggle automatic display of the current line number or column number.
@xref{Optional Mode Line}.
@item M-=
-Display the number of lines in the region (@code{count-lines-region}).
address@hidden, for information about the region.
-
address@hidden C-x l
-Display the number of lines in the current page
-(@code{count-lines-page}). @xref{Pages}.
-
address@hidden M-x count-words-region
-Display the number of words in the region.
+Display the number of lines, words, and characters that are present in
+the region (@code{count-words-region}). @xref{Mark}, for information
+about the region.
+
address@hidden M-x count-words
+Display the number of lines, words, and characters that are present in
+the buffer. If the region is active (@pxref{Mark}), display the
+numbers for the region instead.
+
@item C-x =
Display the character code of character after point, character position of
point, and column of point (@code{what-cursor-position}).
@@ -602,7 +600,6 @@
@xref{Optional Mode Line}.
@end table
address@hidden what-page
@findex what-line
@cindex line number commands
@cindex location of point
@@ -616,16 +613,14 @@
@code{what-line} displays both the line number relative to the
narrowed region and the line number relative to the whole buffer.
- @kbd{M-x what-page} counts pages from the beginning of the file, and
-counts lines within the page, showing both numbers in the echo area.
address@hidden
-
@kindex M-=
address@hidden count-lines-region
- @kbd{M-=} (@code{count-lines-region}) displays the number of lines
-in the region (@pxref{Mark}), while @kbd{C-x l}
-(@code{count-lines-page}) counts the lines in the current page
-(@pxref{Pages}).
address@hidden count-words-region
address@hidden count-words
+ @kbd{M-=} (@code{count-words-region}) displays a message reporting
+the number of lines, words, and characters in the region. @kbd{M-x
+count-words} displays a similar message for the entire buffer, or for
+the region if the region is @dfn{active}. @xref{Mark}, for an
+explanation of the region.
@kindex C-x =
@findex what-cursor-position
=== modified file 'doc/emacs/emacs.texi'
--- a/doc/emacs/emacs.texi 2011-10-08 15:08:50 +0000
+++ b/doc/emacs/emacs.texi 2011-10-08 16:37:46 +0000
@@ -264,7 +264,7 @@
* Basic Help:: Asking what a character does.
* Blank Lines:: Making and deleting blank lines.
* Continuation Lines:: How Emacs displays lines too wide for the screen.
-* Position Info:: What page, line, row, or column is point on?
+* Position Info:: What line, row, or column is point on?
* Arguments:: Numeric arguments for repeating a command N times.
* Repeating:: Repeating the previous command quickly.
=== modified file 'doc/emacs/text.texi'
--- a/doc/emacs/text.texi 2011-08-25 16:13:59 +0000
+++ b/doc/emacs/text.texi 2011-10-08 16:37:46 +0000
@@ -332,6 +332,8 @@
commands to move over them and operate on them.
@table @kbd
address@hidden M-x what-page
+Display the page number of point, and the line number within that page.
@item C-x [
Move point to previous page boundary (@code{backward-page}).
@item C-x ]
@@ -342,6 +344,10 @@
Count the lines in this page (@code{count-lines-page}).
@end table
address@hidden what-page
+ @kbd{M-x what-page} counts pages from the beginning of the file, and
+counts lines within the page, showing both numbers in the echo area.
+
@kindex C-x [
@kindex C-x ]
@findex forward-page
=== modified file 'etc/NEWS'
--- a/etc/NEWS 2011-10-08 15:08:50 +0000
+++ b/etc/NEWS 2011-10-08 16:37:46 +0000
@@ -455,7 +455,10 @@
*** M-s C-e in Isearch is now bound to isearch-yank-line.
+++
-** New command `count-words-region'. This does what you expect.
+** 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.
** The default value of `backup-by-copying-when-mismatch' is now t.
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2011-10-08 14:01:55 +0000
+++ b/lisp/ChangeLog 2011-10-08 16:37:46 +0000
@@ -1,3 +1,15 @@
+2011-10-08 Chong Yidong <address@hidden>
+
+ * simple.el (count-words-region): Always count in the region.
+ Report the number of lines and characters too.
+ (count-words): New command, which counts in the buffer if the
+ region is inactive, as count-words-region used to.
+ (count-words--message): New function. Handle plurals.
+ (count-lines-region): Make it an alias for count-words-region.
+
+ * bindings.el (esc-map): Replace count-lines-region with
+ count-words-region.
+
2011-10-08 Martin Rudalics <address@hidden>
* window.el (window--delete): Delete dedicated frame
=== modified file 'lisp/bindings.el'
--- a/lisp/bindings.el 2011-10-07 16:05:10 +0000
+++ b/lisp/bindings.el 2011-10-08 16:37:46 +0000
@@ -773,7 +773,7 @@
(define-key ctl-x-map "\C-o" 'delete-blank-lines)
(define-key esc-map " " 'just-one-space)
(define-key esc-map "z" 'zap-to-char)
-(define-key esc-map "=" 'count-lines-region)
+(define-key esc-map "=" 'count-words-region)
(define-key ctl-x-map "=" 'what-cursor-position)
(define-key esc-map ":" 'eval-expression)
;; Define ESC ESC : like ESC : for people who type ESC ESC out of habit.
=== modified file 'lisp/simple.el'
--- a/lisp/simple.el 2011-10-01 20:32:01 +0000
+++ b/lisp/simple.el 2011-10-08 16:37:46 +0000
@@ -945,28 +945,46 @@
(forward-line (1- line)))))
(defun count-words-region (start end)
- "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))
+ "Return the number of words between START and END.
+If called interactively, print a message reporting the number of
+lines, words, and characters in the region."
+ (interactive "r")
+ (let ((words 0))
(save-excursion
(save-restriction
(narrow-to-region start end)
(goto-char (point-min))
(while (forward-word 1)
- (setq count (1+ count)))))
+ (setq words (1+ words)))))
(when (called-interactively-p 'interactive)
- (message "%s has %d words"
- (if (use-region-p) "Region" "Buffer")
- count))
- count))
-
-(defun count-lines-region (start end)
- "Print number of lines and characters in the region."
- (interactive "r")
- (message "Region has %d lines, %d characters"
- (count-lines start end) (- end start)))
+ (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)
(defun what-line ()
"Print the current buffer line number and narrowed line number of point."
- [Emacs-diffs] /srv/bzr/emacs/trunk r106028: Rework count-words-region. New command count-words.,
Chong Yidong <=