[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how-many/count-matches for non-interactive use

From: Alexander Pohoyda
Subject: Re: how-many/count-matches for non-interactive use
Date: 15 Oct 2004 17:30:08 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Richard Stallman <address@hidden> 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."
-   (keep-lines-read-args "How many matches for (regexp): "))
+   (append (keep-lines-read-args "How many matches for (regexp): ")
+          '(nil nil t)))
     (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 <address@hidden>
PGP Key fingerprint: 7F C9 CC 5A 75 CD 89 72  15 54 5F 62 20 23 C6 44

reply via email to

[Prev in Thread] Current Thread [Next in Thread]