From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Alexander Pohoyda Newsgroups: gmane.emacs.devel Subject: Re: how-many/count-matches for non-interactive use Date: 15 Oct 2004 17:30:08 +0200 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <87hdowuhhb.fsf@oak.pohoyda.family> References: <87pt3m5vqk.fsf@oak.pohoyda.family> <874qkwmr5w.fsf@oak.pohoyda.family> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1097854326 18734 80.91.229.6 (15 Oct 2004 15:32:06 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 15 Oct 2004 15:32:06 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Oct 15 17:31:53 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CIU3b-0000iN-00 for ; Fri, 15 Oct 2004 17:31:52 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CIUAl-0000se-03 for ged-emacs-devel@m.gmane.org; Fri, 15 Oct 2004 11:39:15 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CIUA5-0000eh-7I for emacs-devel@gnu.org; Fri, 15 Oct 2004 11:38:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CIUA4-0000eM-Ih for emacs-devel@gnu.org; Fri, 15 Oct 2004 11:38:32 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CIUA4-0000eB-DQ for emacs-devel@gnu.org; Fri, 15 Oct 2004 11:38:32 -0400 Original-Received: from [213.165.64.20] (helo=mail.gmx.net) by monty-python.gnu.org with smtp (Exim 4.34) id 1CIU2A-0005Qz-F0 for emacs-devel@gnu.org; Fri, 15 Oct 2004 11:30:22 -0400 Original-Received: (qmail 32004 invoked by uid 65534); 15 Oct 2004 15:30:21 -0000 Original-Received: from p50843BF5.dip0.t-ipconnect.de (EHLO www2.gmx.net) (80.132.59.245) by mail.gmx.net (mp026) with SMTP; 15 Oct 2004 17:30:21 +0200 X-Authenticated: #14602519 Original-Received: from oak.pohoyda.family (localhost [127.0.0.1]) by www2.gmx.net (8.12.10/8.12.10) with ESMTP id i9FFU96U000456; Fri, 15 Oct 2004 17:30:14 +0200 (CEST) (envelope-from alexander.pohoyda@gmx.net) Original-Received: (from apog@localhost) by oak.pohoyda.family (8.12.10/8.12.10/Submit) id i9FFU8Fm000453; Fri, 15 Oct 2004 17:30:08 +0200 (CEST) (envelope-from alexander.pohoyda@gmx.net) X-Authentication-Warning: oak.pohoyda.family: apog set sender to alexander.pohoyda@gmx.net using -f Original-To: rms@gnu.org In-Reply-To: Original-Lines: 65 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:28439 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:28439 Richard Stallman writes: > (defun how-many (regexp &optional rstart rend) > "..." > (interactive > (keep-lines-read-args "How many matches for (regexp): ")) > > How do I use "p" here? > > Since it is using Lisp code, you just do it with more Lisp code. Add > a t to the list in a place that corresponds to where the new extra arg > gets its value. Like this? Index: replace.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/replace.el,v retrieving revision 1.171 diff -u -r1.171 replace.el --- replace.el 30 May 2004 21:50:35 -0000 1.171 +++ replace.el 15 Oct 2004 15:30:02 -0000 @@ -457,8 +457,8 @@ (progn (forward-line 1) (point))))))) -(defun how-many (regexp &optional rstart rend) - "Print number of matches for REGEXP following point. +(defun how-many (regexp &optional rstart rend verbose) + "Return the number of matches for REGEXP following point. If REGEXP contains upper case characters (excluding those preceded by `\\'), the matching is case-sensitive. @@ -467,10 +467,14 @@ Interactively, in Transient Mark mode when the mark is active, operate on the contents of the region. Otherwise, operate from point to the -end of the buffer." +end of the buffer. + +If VERBOSE is t (or the function is called interactively), issue a message +with the number of matches." (interactive - (keep-lines-read-args "How many matches for (regexp): ")) + (append (keep-lines-read-args "How many matches for (regexp): ") + '(nil nil t))) (save-excursion (if rstart (goto-char (min rstart rend)) @@ -490,7 +494,8 @@ (if (= opoint (point)) (forward-char 1) (setq count (1+ count)))) - (message "%d occurrences" count)))) + (when verbose (message "%d occurrences" count)) + count))) (defvar occur-mode-map -- Alexander Pohoyda PGP Key fingerprint: 7F C9 CC 5A 75 CD 89 72 15 54 5F 62 20 23 C6 44