From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Reuben Thomas Newsgroups: gmane.emacs.bugs Subject: bug#9429: 24.0.50; Extended count-words Date: Wed, 7 Sep 2011 12:20:47 +0100 Message-ID: References: <87pqjhfujk.fsf@sc3d.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1315394482 31654 80.91.229.12 (7 Sep 2011 11:21:22 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 7 Sep 2011 11:21:22 +0000 (UTC) Cc: 9429@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Sep 07 13:21:18 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R1GBu-0008Im-N0 for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Sep 2011 13:21:14 +0200 Original-Received: from localhost ([::1]:34291 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R1GBu-0001kS-6y for geb-bug-gnu-emacs@m.gmane.org; Wed, 07 Sep 2011 07:21:14 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:48601) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R1GBr-0001kJ-DY for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2011 07:21:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R1GBq-0006ma-8C for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2011 07:21:11 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48787) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R1GBq-0006mW-2L for bug-gnu-emacs@gnu.org; Wed, 07 Sep 2011 07:21:10 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1R1GFa-000255-0a; Wed, 07 Sep 2011 07:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Reuben Thomas Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 07 Sep 2011 11:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 9429 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 9429-submit@debbugs.gnu.org id=B9429.13153946917977 (code B ref 9429); Wed, 07 Sep 2011 11:25:01 +0000 Original-Received: (at 9429) by debbugs.gnu.org; 7 Sep 2011 11:24:51 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1R1GFP-00024b-Dt for submit@debbugs.gnu.org; Wed, 07 Sep 2011 07:24:51 -0400 Original-Received: from exprod7og111.obsmtp.com ([64.18.2.175]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1R1GFK-00024S-Up for 9429@debbugs.gnu.org; Wed, 07 Sep 2011 07:24:48 -0400 Original-Received: from mail-yi0-f41.google.com ([209.85.218.41]) (using TLSv1) by exprod7ob111.postini.com ([64.18.6.12]) with SMTP ID DSNKTmdTkObvOvESERtfx7TpTNgz1M1W9I5/@postini.com; Wed, 07 Sep 2011 04:20:54 PDT Original-Received: by yic24 with SMTP id 24so170905yic.0 for <9429@debbugs.gnu.org>; Wed, 07 Sep 2011 04:20:48 -0700 (PDT) Original-Received: by 10.231.8.69 with SMTP id g5mr11086401ibg.42.1315394447853; Wed, 07 Sep 2011 04:20:47 -0700 (PDT) Original-Received: by 10.231.59.129 with HTTP; Wed, 7 Sep 2011 04:20:47 -0700 (PDT) In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 07 Sep 2011 07:25:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:50658 Archived-At: On 7 September 2011 02:51, Stefan Monnier wrote: >> It seems to me that it could, however, replace count-words-region >> (ideally, from my point of view, with a =93wc=94 convenience alias), and= I=92d >> be happy to supply such a definition. > > That would be good, yes. =A0I don't see a need for a `wc' alias, tho. The point of the alias is that it's quick to type. This is a command which, like cd, is unlikely to be bound to a keystroke, but is used often enough that having a short name is beneficial. Also like cd, it has a common short name. > PS: Note that the (use-region-p) check should be within the `interactive' > spec rather than within the function body Wow, I had no idea you could do that! Revised version: (defun count-words-region (start end) "Print the number of words in the region or buffer. When called interactively, the word count is printed in echo area, unless a prefix argument is given." (interactive (if (use-region-p) (list (region-beginning) (region-end)) (list (point-min) (point-max)))) (let ((count 0)) (save-excursion (save-restriction (narrow-to-region start end) (goto-char (point-min)) (while (forward-word 1) (setq count (1+ count))))) (if (or (not (called-interactively-p 'interactive)) current-prefix-arg) (insert-string (number-to-string count)) (message "%s has %d words" (if (use-region-p) "Region" "Buffer") count)))) --=20 http://rrt.sc3d.org