emacs-devel
[Top][All Lists]
Advanced

[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: 16 Oct 2004 23:49:32 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50

Richard Stallman <address@hidden> writes:

>     > 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?
> 
> It looks right to me, assuming that keep-lines-read-args
> returns a list of one element (which it currently does).
> You might instead do (list (car (keep-lines-read-args...)) nil nil t)
> to make it clear you're taking just one arg value from that.

Yes, I was considering that style too.  So here it goes.

Would somebody please install the change?  Thank you.


2004-10-16  Alexander Pohoyda  <address@hidden> (tiny change)

        * replace.el (how-many): New VERBOSE argument, which is used
        to suppress the message for non-interactive use.


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  16 Oct 2004 20:12:49 -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): "))
+   (list (car (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 <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]