aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-10-08 12:37:46 -0400
committerChong Yidong2011-10-08 12:37:46 -0400
commitb2b0776e50cd07bc3fbe1548fc258d68a1dbbee8 (patch)
treeca33e46f624b6171b21ee79d9824e62bd88682d0
parent27a16462454d7f45a0b1c65c0b0b2ed76091e11b (diff)
downloademacs-b2b0776e50cd07bc3fbe1548fc258d68a1dbbee8.tar.gz
emacs-b2b0776e50cd07bc3fbe1548fc258d68a1dbbee8.zip
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.
-rw-r--r--doc/emacs/ChangeLog7
-rw-r--r--doc/emacs/basic.texi39
-rw-r--r--doc/emacs/emacs.texi2
-rw-r--r--doc/emacs/text.texi6
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/bindings.el2
-rw-r--r--lisp/simple.el50
8 files changed, 82 insertions, 41 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index a8238f24aee..6fec2e486bc 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,5 +1,12 @@
12011-10-08 Chong Yidong <cyd@stupidchicken.com> 12011-10-08 Chong Yidong <cyd@stupidchicken.com>
2 2
3 * basic.texi (Position Info): Omit page commands. Document
4 count-words-region and count-words.
5
6 * text.texi (Pages): Move what-page documentation here.
7
82011-10-08 Chong Yidong <cyd@stupidchicken.com>
9
3 * mini.texi (Minibuffer File): Minor copyedits. Use xref to 10 * mini.texi (Minibuffer File): Minor copyedits. Use xref to
4 Remote Files node instead of linking directly to the Tramp manual. 11 Remote Files node instead of linking directly to the Tramp manual.
5 (Minibuffer Edit): Add xref to Blank Lines. 12 (Minibuffer Edit): Add xref to Blank Lines.
diff --git a/doc/emacs/basic.texi b/doc/emacs/basic.texi
index 52f9395cedc..e4e7dadd548 100644
--- a/doc/emacs/basic.texi
+++ b/doc/emacs/basic.texi
@@ -23,7 +23,7 @@ suggest you first run the Emacs learn-by-doing tutorial, by typing
23* Help: Basic Help. Asking what a character does. 23* Help: Basic Help. Asking what a character does.
24* Blank Lines:: Making and deleting blank lines. 24* Blank Lines:: Making and deleting blank lines.
25* Continuation Lines:: How Emacs displays lines too wide for the screen. 25* Continuation Lines:: How Emacs displays lines too wide for the screen.
26* Position Info:: What page, line, row, or column is point on? 26* Position Info:: What line, row, or column is point on?
27* Arguments:: Numeric arguments for repeating a command N times. 27* Arguments:: Numeric arguments for repeating a command N times.
28* Repeating:: Repeating the previous command quickly. 28* Repeating:: Repeating the previous command quickly.
29@end menu 29@end menu
@@ -569,28 +569,26 @@ logical lines. @xref{Visual Line Mode}.
569@section Cursor Position Information 569@section Cursor Position Information
570 570
571 Here are commands to get information about the size and position of 571 Here are commands to get information about the size and position of
572parts of the buffer, and to count lines. 572parts of the buffer, and to count words and lines.
573 573
574@table @kbd 574@table @kbd
575@item M-x what-page
576Display the page number of point, and the line number within that page.
577@item M-x what-line 575@item M-x what-line
578Display the line number of point in the whole buffer. 576Display the line number of point.
579@item M-x line-number-mode 577@item M-x line-number-mode
580@itemx M-x column-number-mode 578@itemx M-x column-number-mode
581Toggle automatic display of the current line number or column number. 579Toggle automatic display of the current line number or column number.
582@xref{Optional Mode Line}. 580@xref{Optional Mode Line}.
583 581
584@item M-= 582@item M-=
585Display the number of lines in the region (@code{count-lines-region}). 583Display the number of lines, words, and characters that are present in
586@xref{Mark}, for information about the region. 584the region (@code{count-words-region}). @xref{Mark}, for information
585about the region.
587 586
588@item C-x l 587@item M-x count-words
589Display the number of lines in the current page 588Display the number of lines, words, and characters that are present in
590(@code{count-lines-page}). @xref{Pages}. 589the buffer. If the region is active (@pxref{Mark}), display the
590numbers for the region instead.
591 591
592@item M-x count-words-region
593Display the number of words in the region.
594@item C-x = 592@item C-x =
595Display the character code of character after point, character position of 593Display the character code of character after point, character position of
596point, and column of point (@code{what-cursor-position}). 594point, and column of point (@code{what-cursor-position}).
@@ -602,7 +600,6 @@ Toggle automatic display of the size of the buffer.
602@xref{Optional Mode Line}. 600@xref{Optional Mode Line}.
603@end table 601@end table
604 602
605@findex what-page
606@findex what-line 603@findex what-line
607@cindex line number commands 604@cindex line number commands
608@cindex location of point 605@cindex location of point
@@ -616,16 +613,14 @@ the accessible portion (@pxref{Narrowing}). By contrast,
616@code{what-line} displays both the line number relative to the 613@code{what-line} displays both the line number relative to the
617narrowed region and the line number relative to the whole buffer. 614narrowed region and the line number relative to the whole buffer.
618 615
619 @kbd{M-x what-page} counts pages from the beginning of the file, and
620counts lines within the page, showing both numbers in the echo area.
621@xref{Pages}.
622
623@kindex M-= 616@kindex M-=
624@findex count-lines-region 617@findex count-words-region
625 @kbd{M-=} (@code{count-lines-region}) displays the number of lines 618@findex count-words
626in the region (@pxref{Mark}), while @kbd{C-x l} 619 @kbd{M-=} (@code{count-words-region}) displays a message reporting
627(@code{count-lines-page}) counts the lines in the current page 620the number of lines, words, and characters in the region. @kbd{M-x
628(@pxref{Pages}). 621count-words} displays a similar message for the entire buffer, or for
622the region if the region is @dfn{active}. @xref{Mark}, for an
623explanation of the region.
629 624
630@kindex C-x = 625@kindex C-x =
631@findex what-cursor-position 626@findex what-cursor-position
diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi
index 2107b6926b9..49b91c72da4 100644
--- a/doc/emacs/emacs.texi
+++ b/doc/emacs/emacs.texi
@@ -264,7 +264,7 @@ Basic Editing Commands
264* Basic Help:: Asking what a character does. 264* Basic Help:: Asking what a character does.
265* Blank Lines:: Making and deleting blank lines. 265* Blank Lines:: Making and deleting blank lines.
266* Continuation Lines:: How Emacs displays lines too wide for the screen. 266* Continuation Lines:: How Emacs displays lines too wide for the screen.
267* Position Info:: What page, line, row, or column is point on? 267* Position Info:: What line, row, or column is point on?
268* Arguments:: Numeric arguments for repeating a command N times. 268* Arguments:: Numeric arguments for repeating a command N times.
269* Repeating:: Repeating the previous command quickly. 269* Repeating:: Repeating the previous command quickly.
270 270
diff --git a/doc/emacs/text.texi b/doc/emacs/text.texi
index 0b0e4867ae5..96ccaa2b3c4 100644
--- a/doc/emacs/text.texi
+++ b/doc/emacs/text.texi
@@ -332,6 +332,8 @@ pages are often meaningful divisions of the file, Emacs provides
332commands to move over them and operate on them. 332commands to move over them and operate on them.
333 333
334@table @kbd 334@table @kbd
335@item M-x what-page
336Display the page number of point, and the line number within that page.
335@item C-x [ 337@item C-x [
336Move point to previous page boundary (@code{backward-page}). 338Move point to previous page boundary (@code{backward-page}).
337@item C-x ] 339@item C-x ]
@@ -342,6 +344,10 @@ Put point and mark around this page (or another page) (@code{mark-page}).
342Count the lines in this page (@code{count-lines-page}). 344Count the lines in this page (@code{count-lines-page}).
343@end table 345@end table
344 346
347@findex what-page
348 @kbd{M-x what-page} counts pages from the beginning of the file, and
349counts lines within the page, showing both numbers in the echo area.
350
345@kindex C-x [ 351@kindex C-x [
346@kindex C-x ] 352@kindex C-x ]
347@findex forward-page 353@findex forward-page
diff --git a/etc/NEWS b/etc/NEWS
index 41870bf53cc..e3453b3a92f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -455,7 +455,10 @@ isearch-yank-kill.
455*** M-s C-e in Isearch is now bound to isearch-yank-line. 455*** M-s C-e in Isearch is now bound to isearch-yank-line.
456 456
457+++ 457+++
458** New command `count-words-region'. This does what you expect. 458** New commands `count-words-region' and `count-words'.
459
460*** `count-lines-region' is now an alias for `count-words-region',
461bound to M-=, which shows the number of lines, words, and characters.
459 462
460** The default value of `backup-by-copying-when-mismatch' is now t. 463** The default value of `backup-by-copying-when-mismatch' is now t.
461 464
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 076749197e0..611219cb5ec 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,15 @@
12011-10-08 Chong Yidong <cyd@stupidchicken.com>
2
3 * simple.el (count-words-region): Always count in the region.
4 Report the number of lines and characters too.
5 (count-words): New command, which counts in the buffer if the
6 region is inactive, as count-words-region used to.
7 (count-words--message): New function. Handle plurals.
8 (count-lines-region): Make it an alias for count-words-region.
9
10 * bindings.el (esc-map): Replace count-lines-region with
11 count-words-region.
12
12011-10-08 Martin Rudalics <rudalics@gmx.at> 132011-10-08 Martin Rudalics <rudalics@gmx.at>
2 14
3 * window.el (window--delete): Delete dedicated frame 15 * window.el (window--delete): Delete dedicated frame
diff --git a/lisp/bindings.el b/lisp/bindings.el
index c056fce1e60..1a10d117987 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -773,7 +773,7 @@ if `inhibit-field-text-motion' is non-nil."
773(define-key ctl-x-map "\C-o" 'delete-blank-lines) 773(define-key ctl-x-map "\C-o" 'delete-blank-lines)
774(define-key esc-map " " 'just-one-space) 774(define-key esc-map " " 'just-one-space)
775(define-key esc-map "z" 'zap-to-char) 775(define-key esc-map "z" 'zap-to-char)
776(define-key esc-map "=" 'count-lines-region) 776(define-key esc-map "=" 'count-words-region)
777(define-key ctl-x-map "=" 'what-cursor-position) 777(define-key ctl-x-map "=" 'what-cursor-position)
778(define-key esc-map ":" 'eval-expression) 778(define-key esc-map ":" 'eval-expression)
779;; Define ESC ESC : like ESC : for people who type ESC ESC out of habit. 779;; Define ESC ESC : like ESC : for people who type ESC ESC out of habit.
diff --git a/lisp/simple.el b/lisp/simple.el
index c81385680bf..af6d855d9c0 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -945,28 +945,46 @@ rather than line counts."
945 (forward-line (1- line))))) 945 (forward-line (1- line)))))
946 946
947(defun count-words-region (start end) 947(defun count-words-region (start end)
948 "Count the number of words in the active region. 948 "Return the number of words between START and END.
949If the region is not active, counts the number of words in the buffer." 949If called interactively, print a message reporting the number of
950 (interactive (if (use-region-p) (list (region-beginning) (region-end)) 950lines, words, and characters in the region."
951 (list (point-min) (point-max)))) 951 (interactive "r")
952 (let ((count 0)) 952 (let ((words 0))
953 (save-excursion 953 (save-excursion
954 (save-restriction 954 (save-restriction
955 (narrow-to-region start end) 955 (narrow-to-region start end)
956 (goto-char (point-min)) 956 (goto-char (point-min))
957 (while (forward-word 1) 957 (while (forward-word 1)
958 (setq count (1+ count))))) 958 (setq words (1+ words)))))
959 (when (called-interactively-p 'interactive) 959 (when (called-interactively-p 'interactive)
960 (message "%s has %d words" 960 (count-words--message "Region"
961 (if (use-region-p) "Region" "Buffer") 961 (count-lines start end)
962 count)) 962 words
963 count)) 963 (- end start)))
964 964 words))
965(defun count-lines-region (start end) 965
966 "Print number of lines and characters in the region." 966(defun count-words ()
967 (interactive "r") 967 "Display the number of lines, words, and characters in the buffer.
968 (message "Region has %d lines, %d characters" 968In Transient Mark mode when the mark is active, display the
969 (count-lines start end) (- end start))) 969number of lines, words, and characters in the region."
970 (interactive)
971 (if (use-region-p)
972 (call-interactively 'count-words-region)
973 (let* ((beg (point-min))
974 (end (point-max))
975 (lines (count-lines beg end))
976 (words (count-words-region beg end))
977 (chars (- end beg)))
978 (count-words--message "Buffer" lines words chars))))
979
980(defun count-words--message (str lines words chars)
981 (message "%s has %d line%s, %d word%s, and %d character%s."
982 str
983 lines (if (= lines 1) "" "s")
984 words (if (= words 1) "" "s")
985 chars (if (= chars 1) "" "s")))
986
987(defalias 'count-lines-region 'count-words-region)
970 988
971(defun what-line () 989(defun what-line ()
972 "Print the current buffer line number and narrowed line number of point." 990 "Print the current buffer line number and narrowed line number of point."