From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.bugs Subject: bug#9429: 24.0.50; Extended count-words Date: Fri, 09 Sep 2011 23:03:20 -0400 Message-ID: References: <87pqjhfujk.fsf@sc3d.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1315623843 16667 80.91.229.12 (10 Sep 2011 03:04:03 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 10 Sep 2011 03:04:03 +0000 (UTC) Cc: 9429@debbugs.gnu.org To: Reuben Thomas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Sep 10 05:03:59 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 1R2DrL-0003AF-5N for geb-bug-gnu-emacs@m.gmane.org; Sat, 10 Sep 2011 05:03:59 +0200 Original-Received: from localhost ([::1]:40328 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2DrK-0007vX-Ig for geb-bug-gnu-emacs@m.gmane.org; Fri, 09 Sep 2011 23:03:58 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:54917) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2DrI-0007vS-6k for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2011 23:03:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R2DrH-0000i9-1k for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2011 23:03:56 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60037) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2DrG-0000i5-V8 for bug-gnu-emacs@gnu.org; Fri, 09 Sep 2011 23:03:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1R2DvG-0004V4-5b; Fri, 09 Sep 2011 23:08:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 10 Sep 2011 03:08:02 +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.131562405117262 (code B ref 9429); Sat, 10 Sep 2011 03:08:02 +0000 Original-Received: (at 9429) by debbugs.gnu.org; 10 Sep 2011 03:07:31 +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 1R2Dul-0004UL-4F for submit@debbugs.gnu.org; Fri, 09 Sep 2011 23:07:31 -0400 Original-Received: from ironport2-out.teksavvy.com ([206.248.154.183] helo=ironport2-out.pppoe.ca) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1R2Duj-0004UE-FK for 9429@debbugs.gnu.org; Fri, 09 Sep 2011 23:07:30 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkIFAFTSak64rwMJ/2dsb2JhbABChFWhTYF1eYFSAQEEASMzIwULCw4MAhgOAgIUGA0kiAmlBpFsgSyEMYERBKAvhEI X-IronPort-AV: E=Sophos;i="4.68,360,1312171200"; d="scan'208";a="135429999" Original-Received: from 184-175-3-9.dsl.teksavvy.com (HELO pastel.home) ([184.175.3.9]) by ironport2-out.pppoe.ca with ESMTP/TLS/ADH-AES256-SHA; 09 Sep 2011 23:03:21 -0400 Original-Received: by pastel.home (Postfix, from userid 20848) id A7A87589E5; Fri, 9 Sep 2011 23:03:20 -0400 (EDT) In-Reply-To: (Reuben Thomas's message of "Wed, 7 Sep 2011 12:20:47 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 09 Sep 2011 23:08: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:50775 Archived-At: >>> It seems to me that it could, however, replace count-words-region >>> (ideally, from my point of view, with a =E2=80=9Cwc=E2=80=9D convenienc= e alias), and I=E2=80=99d >>> be happy to supply such a definition. >> That would be good, yes. =C2=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. I'm not completely sure yet, and we're already in feature freeze, so I'd rather not commit on giving away such a short name. You can use M-x c-w (which I've bound to M-TAB) which doesn't seem that bad. It won't work at first (because it will just use the shortest completion) but on the second use it will (because it will give preference to the most recently matching completion). If we rename count-word-region to count-words then it may even work right away. > 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-ar= g) > (insert-string (number-to-string count)) > (message "%s has %d words" > (if (use-region-p) "Region" "Buffer") > count)))) I installed a half-way version (see below) which lacks the "insert count at point" feature, because I'm not completely sure I want to spend the C-u on this feature. And since we're in feature freeze, I wanted to keep it to the very minimum "obviously good". Stefan =3D=3D=3D modified file 'lisp/simple.el' --- lisp/simple.el 2011-09-09 08:59:51 +0000 +++ lisp/simple.el 2011-09-10 03:00:26 +0000 @@ -938,9 +938,10 @@ (forward-line (1- line))))) =20 (defun count-words-region (start end) - "Print the number of words in the region. -When called interactively, the word count is printed in echo area." - (interactive "r") + "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)) (save-excursion (save-restriction @@ -948,8 +949,10 @@ (goto-char (point-min)) (while (forward-word 1) (setq count (1+ count))))) - (if (called-interactively-p 'interactive) - (message "Region has %d words" count)) + (when (called-interactively-p 'interactive) + (message "%s has %d words" + (if (use-region-p) "Region" "Buffer") + count)) count)) =20 (defun count-lines-region (start end)