diff options
| author | Chong Yidong | 2011-10-08 12:37:46 -0400 |
|---|---|---|
| committer | Chong Yidong | 2011-10-08 12:37:46 -0400 |
| commit | b2b0776e50cd07bc3fbe1548fc258d68a1dbbee8 (patch) | |
| tree | ca33e46f624b6171b21ee79d9824e62bd88682d0 /lisp | |
| parent | 27a16462454d7f45a0b1c65c0b0b2ed76091e11b (diff) | |
| download | emacs-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.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 12 | ||||
| -rw-r--r-- | lisp/bindings.el | 2 | ||||
| -rw-r--r-- | lisp/simple.el | 50 |
3 files changed, 47 insertions, 17 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 076749197e0..611219cb5ec 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,15 @@ | |||
| 1 | 2011-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 | |||
| 1 | 2011-10-08 Martin Rudalics <rudalics@gmx.at> | 13 | 2011-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. |
| 949 | If the region is not active, counts the number of words in the buffer." | 949 | If called interactively, print a message reporting the number of |
| 950 | (interactive (if (use-region-p) (list (region-beginning) (region-end)) | 950 | lines, 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" | 968 | In Transient Mark mode when the mark is active, display the |
| 969 | (count-lines start end) (- end start))) | 969 | number 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." |