help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: When grep-find, show the count of matches


From: Tim Landscheidt
Subject: Re: When grep-find, show the count of matches
Date: Mon, 28 Jun 2010 17:59:05 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

filebat Mark <filebat.mark@gmail.com> wrote:

> Thank you very much, Tim. Sorry for my confusing illustration.

> You have point a good way to solve my problem. Changing grep-process-setup
> seems don't work, so I change the function of grep-find.

> One slight problem is that, since the grep command takes some time, even
> though we define an after-defadive, the function is executed before *grep*
> buffer is stable.

> My workaround is to sleep for some while. No idea whether we have better
> solution.

> (defadvice grep-find (after show-grep())
>  (save-excursion
>    (setq SLEEP_INTERVAL 2)
>    (set-buffer "*grep*")
>    (sleep-for SLEEP_INTERVAL)
>    (message
>     "%d matches found"
>     (- (count-lines (point-min) (point-max)) 6))
>    )
> )
> (ad-activate 'grep-find)
> [...]

No, you should defadvice *around* grep-process-setup, copy
the whole original from the Emacs distribution, and replace
the lambda construct in:

|   (set (make-local-variable 'compilation-exit-message-function)
|        (lambda (status code msg)
|          (if (eq status 'exit)
|              (cond ((zerop code)
|                     '("finished (matches found)\n" . "matched"))
|                    ((= code 1)
|                     '("finished with no matches found\n" . "no match"))
|                    (t
|                     (cons msg code)))
|            (cons msg code))))

with another that inserts the number of matches into the
buffer.

Tim




reply via email to

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