From: Chong Yidong Date: Fri, 10 Aug 2012 16:02:48 +0000 (+0800) Subject: Bind M-= back to count-words-region, and let it accept a prefix arg. X-Git-Tag: emacs-24.2.90~735 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e1293765d95660fc7f2cf0fcb28026d1efa592df;p=emacs.git Bind M-= back to count-words-region, and let it accept a prefix arg. * lisp/bindings.el: Bind M-= back to count-words-region. * lisp/simple.el (count-words-region): Accept a prefix arg for acting on the entire buffer. (count-words--buffer-message): New helper function. --- diff --git a/etc/NEWS b/etc/NEWS index 10dfe408813..2b4b3ed8c25 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -176,7 +176,7 @@ prompts for a column number. ** `mouse-avoidance-banish-position' can now be used to customize `mouse-avoidance-mode' further. -** `M-=' is now bound to `count-words', not `count-words-region'. +** `C-u M-=' now counts lines/words/characters in the entire buffer. ** `C-M-f' and `C-M-b' will now move to the path name separator character when doing minibuffer filename prompts. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 347f7b666f6..b6649d4b37d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2012-08-10 Chong Yidong + + * bindings.el: Bind M-= back to count-words-region. + + * simple.el (count-words-region): Accept a prefix arg for acting + on the entire buffer. + (count-words--buffer-message): New helper function. + 2012-08-10 Stefan Monnier * term/x-win.el (x-menu-bar-open): Always pass last-nonmenu-event. diff --git a/lisp/bindings.el b/lisp/bindings.el index 655cda235b4..e0555a17b15 100644 --- a/lisp/bindings.el +++ b/lisp/bindings.el @@ -793,7 +793,7 @@ if `inhibit-field-text-motion' is non-nil." (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-words) +(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. diff --git a/lisp/simple.el b/lisp/simple.el index 0877f396faa..f644044a430 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -966,16 +966,22 @@ rather than line counts." (re-search-forward "[\n\C-m]" nil 'end (1- line)) (forward-line (1- line))))) -(defun count-words-region (start end) +(defun count-words-region (start end &optional arg) "Count the number of words in the region. If called interactively, print a message reporting the number of -lines, words, and chars in the region. +lines, words, and characters in the region (whether or not the +region is active); with prefix ARG, report for the entire buffer +rather than the region. + If called from Lisp, return the number of words between positions START and END." - (interactive "r") - (if (called-interactively-p 'any) - (count-words--message "Region" start end) - (count-words start end))) + (interactive "r\nP") + (cond ((not (called-interactively-p 'any)) + (count-words start end)) + (arg + (count-words--buffer-message)) + (t + (count-words--message "Region" start end)))) (defun count-words (start end) "Count words between START and END. @@ -999,11 +1005,14 @@ END, without printing any message." ((use-region-p) (call-interactively 'count-words-region)) (t - (count-words--message - (if (= (point-max) (1+ (buffer-size))) - "Buffer" - "Narrowed part of buffer") - (point-min) (point-max))))) + (count-words--buffer-message)))) + +(defun count-words--buffer-message () + (count-words--message + (if (= (point-max) (1+ (buffer-size))) + "Buffer" + "Narrowed part of buffer") + (point-min) (point-max))) (defun count-words--message (str start end) (let ((lines (count-lines start end))